question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule options from implicitly included plugins are not validated

See original GitHub issue

Tell us about your environment

  • ESLint Version: v5.15.3
  • Node Version: v11.12.0
  • npm Version: 6.9.0

What parser (default, Babel-ESLint, etc.) are you using? default (Espree)

Please show your full configuration:

Configuration
{
    "root": true,
    "env": {
        "commonjs": true,
        "es6": true,
        "node": true
    },
    "extends": ["eslint:recommended", "plugin:node/recommended"],
    "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
    },
    "parserOptions": {
        "ecmaVersion": 2018
    },
    "rules": {
        "node/exports-style": ["error", "invalid-option"]
    }
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

const none = require("./doesnt-exist");
$ ./node_modules/.bin/eslint .

What did you expect to happen?

I expected ESLint to report a validation error like so:

$ ./node_modules/.bin/eslint .
Error: /Users/jarrodldavis/source/repos/repro-eslint-validate-issue/explicit-plugin/.eslintrc.json:
	Configuration for rule "node/exports-style" is invalid:
	Value "invalid-option" should be equal to one of the allowed values.

    at validateRuleOptions (/Users/jarrodldavis/source/repos/repro-eslint-validate-issue/explicit-plugin/node_modules/eslint/lib/config/config-validator.js:133:19)
    at Object.keys.forEach.id (/Users/jarrodldavis/source/repos/repro-eslint-validate-issue/explicit-plugin/node_modules/eslint/lib/config/config-validator.js:176:9)
    at Array.forEach (<anonymous>)
    at validateRules (/Users/jarrodldavis/source/repos/repro-eslint-validate-issue/explicit-plugin/node_modules/eslint/lib/config/config-validator.js:175:30)
    at Object.validate (/Users/jarrodldavis/source/repos/repro-eslint-validate-issue/explicit-plugin/node_modules/eslint/lib/config/config-validator.js:262:5)
    at loadFromDisk (/Users/jarrodldavis/source/repos/repro-eslint-validate-issue/explicit-plugin/node_modules/eslint/lib/config/config-file.js:544:19)
    at Object.load (/Users/jarrodldavis/source/repos/repro-eslint-validate-issue/explicit-plugin/node_modules/eslint/lib/config/config-file.js:587:20)
    at Config.getLocalConfigHierarchy (/Users/jarrodldavis/source/repos/repro-eslint-validate-issue/explicit-plugin/node_modules/eslint/lib/config.js:240:44)
    at Config.getConfigHierarchy (/Users/jarrodldavis/source/repos/repro-eslint-validate-issue/explicit-plugin/node_modules/eslint/lib/config.js:192:43)
    at Config.getConfigVector (/Users/jarrodldavis/source/repos/repro-eslint-validate-issue/explicit-plugin/node_modules/eslint/lib/config.js:299:21)

What actually happened? Please include the actual, raw output from ESLint.

The validation error is ignored and ESLint continues as if the plugin option is valid

$ ./node_modules/.bin/eslint .

/Users/jarrodldavis/source/repos/repro-eslint-validate-issue/implicit-plugin/index.js
  1:7   error  'none' is assigned a value but never used  no-unused-vars
  1:22  error  "./doesnt-exist" is not found              node/no-missing-require

✖ 2 problems (2 errors, 0 warnings)

I’ve created a reproduction repository that demonstrates the difference in plugin rule validation behavior when implicitly vs explicitly including a plugin.

I believe I have narrowed it down to this code:

https://github.com/eslint/eslint/blob/a6168f85f9017332777b2bac5af8c4a979e06298/lib/config/config-file.js#L541-L552

https://github.com/eslint/eslint/blob/a6168f85f9017332777b2bac5af8c4a979e06298/lib/config/config-validator.js#L170-L173

It validates the local config (including rule options) before applying config extensions, so the plugin and its rules aren’t loaded into the linter until after the rules enabled by the local config are validated. Since the rules aren’t present at the time of validation, validation is silently skipped.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mysticateacommented, Mar 29, 2019

I confirmed that this reproduced.

And yes, #11546 fixed this bug because it has separated config schema validation and rule option validation. In #11546, ESLint validates config schema when each config file was read and validates rule options and environments when the configuration was determined for each source file (i.e. after all cascading config files, shareable configs, plugins, and parsers are loaded).

0reactions
fvhockneycommented, Apr 4, 2019

Great. #11546 seems to fix the issue for --fix-type as well. I’ll keep my eyes peeled for the releases.

Read more comments on GitHub >

github_iconTop Results From Across the Web

API Reference: ApolloServer - Apollo GraphQL Docs
A valid Schema Definition Language (SDL) string, document, or documents that ... rules should depend only on the operation and the schema, not...
Read more >
Configuration | Stylelint
Plugins are rules or sets of rules built by the community that support methodologies, toolsets, non-standard CSS features, or very specific use cases....
Read more >
Rules - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Linter rules - Dart
Details about the Dart linter and its style rules you can choose. ... dart:html , dart:js and dart:js_util in Flutter packages that are...
Read more >
12 essential ESLint rules for React - LogRocket Blog
In this post, we'll go over these ESLint rules and plugins, including as ... are not being flagged, make sure you have included...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found