Codacy "Found fs.functionName with non literal argument at index 0" error

6.6k Views Asked by At

Error messages and my codes:

Found fs.existsSync with non literal argument at index 0

if (!fs.existsSync(dbFolder)){

Found fs.mkdirSync with non literal argument at index 0

fs.mkdirSync(dbFolder);

Found fs.readFileSync with non literal argument at index 0

const content = JSON.parse(fs.readFileSync(`${this.dbFolder}/${this.dbName}.json`, "utf8"));

Found fs.writeFileSync with non literal argument at index 0

fs.writeFileSync(`${dbFolder}/${dbName}.json`, "{}");
1

There are 1 best solutions below

3
pedrorijo91 On

if you wonder what's the problem, it's in the error message. It's bad practice to use a non literal (a variable) on fs.readFileSync first argument.

See https://github.com/nodesecurity/eslint-plugin-security#detect-non-literal-fs-filename