Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support an "eslint" property for package.json configuration #8589

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/user-guide/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ESLint is designed to be completely configurable, meaning you can turn off every rule and run only with basic syntax validation, or mix and match the bundled rules and your custom rules to make ESLint perfect for your project. There are two primary ways to configure ESLint:

1. **Configuration Comments** - use JavaScript comments to embed configuration information directly into a file.
1. **Configuration Files** - use a JavaScript, JSON or YAML file to specify configuration information for an entire directory and all of its subdirectories. This can be in the form of an [.eslintrc.*](#configuration-file-formats) file or an `eslintConfig` field in a [`package.json`](https://docs.npmjs.com/files/package.json) file, both of which ESLint will look for and read automatically, or you can specify a configuration file on the [command line](command-line-interface).
1. **Configuration Files** - use a JavaScript, JSON or YAML file to specify configuration information for an entire directory and all of its subdirectories. This can be in the form of an [.eslintrc.*](#configuration-file-formats) file or either an `eslint` or `eslintConfig` field in a [`package.json`](https://docs.npmjs.com/files/package.json) file, both of which ESLint will look for and read automatically, or you can specify a configuration file on the [command line](command-line-interface).

There are several pieces of information that can be configured:

Expand Down Expand Up @@ -467,7 +467,7 @@ ESLint supports configuration files in several formats:
* **YAML** - use `.eslintrc.yaml` or `.eslintrc.yml` to define the configuration structure.
* **JSON** - use `.eslintrc.json` to define the configuration structure. ESLint's JSON files also allow JavaScript-style comments.
* **Deprecated** - use `.eslintrc`, which can be either JSON or YAML.
* **package.json** - create an `eslintConfig` property in your `package.json` file and define your configuration there.
* **package.json** - create an `eslint` or `eslintConfig` property in your `package.json` file and define your configuration there.

If there are multiple configuration files in the same directory, ESLint will only use one. The priority order is:

Expand Down
4 changes: 3 additions & 1 deletion lib/config/config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ function loadJSConfigFile(filePath) {
function loadPackageJSONConfigFile(filePath) {
debug(`Loading package.json config file: ${filePath}`);
try {
return loadJSONConfigFile(filePath).eslintConfig || null;
const packageConfig = loadJSONConfigFile(filePath);

return packageConfig.eslint || packageConfig.eslintConfig || null;
} catch (e) {
debug(`Error reading package.json file: ${filePath}`);
e.message = `Cannot read config file: ${filePath}\nError: ${e.message}`;
Expand Down
33 changes: 32 additions & 1 deletion tests/lib/config/config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,38 @@ describe("ConfigFile", () => {
});
});

it("should load fresh information from a package.json file", () => {
it("should load fresh information from a package.json file using `eslint`", () => {
const initialConfig = {
eslint: {
parserOptions: {},
env: {},
globals: {},
rules: {
quotes: [2, "double"]
}
}
},
updatedConfig = {
eslint: {
parserOptions: {},
env: {},
globals: {},
rules: {
quotes: 0
}
}
},
tmpFilename = "package.json",
tmpFilePath = writeTempConfigFile(initialConfig, tmpFilename);
let config = ConfigFile.load(tmpFilePath);

assert.deepEqual(config, initialConfig.eslint);
writeTempConfigFile(updatedConfig, tmpFilename, path.dirname(tmpFilePath));
config = ConfigFile.load(tmpFilePath);
assert.deepEqual(config, updatedConfig.eslint);
});

it("should load fresh information from a package.json file using `eslintConfig`", () => {
const initialConfig = {
eslintConfig: {
parserOptions: {},
Expand Down