Eslint CLIEngine removes empty line between imports incorrectly, but eslint --fix works
See original GitHub issueTell us about your environment
- ESLint Version: 5.0.1
- Node Version: 8.11.1
yarn
version: 1.5.1
What parser (default, Babel-ESLint, etc.) are you using? babel-eslint
Please show your full configuration:
Configuration
const path = require("path");
const config = {
parser: "babel-eslint",
env: {
node: true
},
plugins: ["import"],
rules: {
"import/order": [
"error",
{
groups: [
["builtin", "external"],
"internal",
"parent",
["sibling", "index"]
],
"newlines-between": "always"
}
]
},
settings: {
"import/resolver": {
node: {
root: __dirname
},
alias: [["appalias", path.resolve(__dirname, "src/app")]]
}
}
};
module.exports = config;
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
Run eslint CLIEngine on a source file using import/order
rule that requires newline between import groups.
run-eslint-cli.js
const eslint = require("eslint");
const config = require("./.eslintrc.js");
const CLIEngine = eslint.CLIEngine;
const cli = new CLIEngine({
...config,
useEslintrc: false,
fix: true
});
const results = cli.executeOnFiles(["./src/example.js"]);
CLIEngine.outputFixes(results);
console.info("Results:\n" + JSON.stringify(results, null, 2));
src/example.js (file being formatted)
const fs = require("fs");
const main = require("src/main");
const app = require("appalias");
const packageJson = require("../package.json");
const mainSibling = require("./main");
Reproduction repository:
https://github.com/amosyuen/prettier-eslint-import-empty-line-removal
What did you expect to happen?
eslint shouldn’t remove the empty line between const main = require("src/main");
and const app = require("appalias");
.
What actually happened? Please include the actual, raw output from ESLint.
Eslint CLI engine incorrectly removes the empty line between const main = require("src/main");
and const app = require("appalias");
. This causes an eslint error.
However, running the eslint cli directly works. yarn eslint --fix
will correctly add back the empty line.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:11 (5 by maintainers)
Top GitHub Comments
So after some reading around I think I see the problem. Your 4th case for CLIEngine should correspond to the broken case. I didn’t realize it because you had an extra
config:
in there, which I think is a typo.Looking at https://eslint.org/docs/developer-guide/nodejs-api#cliengine, seems like
settings
isn’t a field on the options, so that would explain why my eslint settings aren’t used. I’m guessing instead ofconfig
field, I think you meant to useconfigFile
field.If that’s true then seems like the problem is I was assuming the CLIEngine options should support all the same fields as a normal eslintrc file. While the documentation doesn’t list all the fields, this seems like an easy and error prone thing for developers to do. Perhaps some extra documentation warning that it doesn’t support all the same fields as eslintrc would be nice. Note: this is exactly how
prettier-eslint
uses CLIEngine, which is what lead me to file this bug in the first place.For reference, the bug at prettier-eslint https://github.com/prettier/prettier-eslint/issues/181
Hey, sorry didn’t get back to this in a while, but I think the specific problem is eslint supports only a subset of config options directly on the settings or a path to a config file with full settings. The action item is that eslint should support all config options directly on the settings.