Wk-notes-01-06-eslint-finalise
Correctly write json to file
fs.writeFile(outputFilename, JSON.stringify(myData, null, 4), function(err) {
if(err) {
console.log(err);
} else {
console.log("JSON saved to " + outputFilename);
}
});** If using CLI-COMMAND > File-Name.json it could went wrong.
eslint pitfall in custom CLI tool:
In cli.js, passing default fix as null to eslint.
yargs.command(
"eslint",
"run the linter",
yargs => {
yargs
.option("fix", {
describe: "enable auto fixing option in eslint",
// ------***** BELOW *****---------
default: null
// ------***** ABOVE *****---------
});
},
argv => {
const eslint = require("./eslint").default;
eslint(argv);
}
)Consuming fix directly in CLIEngine
The following code, will be transpiled by babel to
Key bug : null will be treated as true and the fixed file will be listed on the fly. The check in fixer is
Remember to use false as the defailt fix flag.
Last updated
Was this helpful?