Code Monkey home page Code Monkey logo

Comments (6)

randycoulman avatar randycoulman commented on July 19, 2024

I've been thinking more about this as I think about implementing it, and I realize that eslint already warns when deprecated rules are in use. Is this feature useful enough to implement here anyway? Or should I just close the issue?

from eslint-find-rules.

ljharb avatar ljharb commented on July 19, 2024

I think it's still useful to get a zero/nonzero exit code based on the config files, without having to actually run eslint.

from eslint-find-rules.

randycoulman avatar randycoulman commented on July 19, 2024

Yeah, good point. I'll keep it open and work on it when I get a chance.

from eslint-find-rules.

alexilyaev avatar alexilyaev commented on July 19, 2024

ESLint doesn't warn when using deprecated rules in the config, only when using rules that don't exist anymore.

I've got 2 deprecated rules here: https://github.com/alexilyaev/react-es6-starter
newline-after-var and newline-before-return
Running eslint -c .eslintrc --ignore-path .gitignore . doesn't show me any warning.

I think an option to show currently configured deprecated rules is very useful.
We actually have no way of checking it right now

I'm doing something similar with stylelint-find-rules.
Can show configured deprecated rules.

Just tried filtering the currentRules:

  this.getCurrentDeprecatedRules = function () {
    var rules = eslint.linter.getRules();

    return getSortedRules(currentRules).filter(function (rule) {
      return _isDeprecated(rules.get(rule) || '')
    });
  };

It worked, though if I have extends, it counts rules from them as well.
Perhaps ignore extends somehow.

from eslint-find-rules.

ta2edchimp avatar ta2edchimp commented on July 19, 2024

A flag to ignore a config's "extends" would be nice.
But atm, only manipulating the input (removing the "extends" property of the config to be loaded) before actually loading the configuration via ESLint's CLIEngine comes to my mind.

from eslint-find-rules.

alexilyaev avatar alexilyaev commented on July 19, 2024

@ta2edchimp @randycoulman So, after 2 years, I find myself back here :-)

I'm trying to validate user configured rules to not have deprecated rules.
This is useful when upgrading configs/plugins which deprecate certain rules.

Right now running eslint-find-rules -d .eslintrc will show deprecated rules not only from user configured rules, but also from extends.

I dug into the code and found it's not so simple to mitigate.
At _getConfigs we use cliEngine.getConfigForFile which loads the configFile and merges all extends on top of it.
Which means that currentRuleNames will already include rules from extends and not only the user defined rules.
And then deprecatedRuleNames can show rules that were not defined by the user.

This happened to me with eslint-config-prettier:
prettier/eslint-config-prettier#112

I tried to dig into eslint's CLIEngine code as well.
Looks like there's a cascade of configs that are being loaded and merged under CascadingConfigArrayFactory.
But eventually our configFile is loaded with configArrayFactory.loadFile, which runs _normalizeConfigData, which then loads and merges the extends and other things.

The only thing I came up with is this:

const { ConfigArrayFactory } = require('eslint/lib/cli-engine/config-array-factory.js');
const configArrayFactory = new ConfigArrayFactory();
configArrayFactory.loadFile(configFile, { name: "UserConfig" });

Which gives us an Array of configs... the user config, extends, overrides, etc.
From here it might be possible to filter out the extends and get a merged config only from user defined rules.

Here's how it looks like
[
  { name:
     'UserConfig » eslint-config-ai/react » eslint-config-prettier/react',
    filePath:
     '/Users/alex/www/Node/Personal/eslint-config-ai/node_modules/eslint-config-prettier/react.js',
    criteria: null,
    env: undefined,
    globals: undefined,
    noInlineConfig: undefined,
    parser: undefined,
    parserOptions: undefined,
    plugins: undefined,
    processor: undefined,
    reportUnusedDisableDirectives: undefined,
    root: undefined,
    rules:
     { 'react/jsx-child-element-spacing': 'off',
       'react/jsx-closing-bracket-location': 'off',
       'react/jsx-closing-tag-location': 'off',
       'react/jsx-curly-newline': 'off',
       'react/jsx-curly-spacing': 'off',
       'react/jsx-equals-spacing': 'off',
       'react/jsx-first-prop-new-line': 'off',
       'react/jsx-indent': 'off',
       'react/jsx-indent-props': 'off',
       'react/jsx-max-props-per-line': 'off',
       'react/jsx-one-expression-per-line': 'off',
       'react/jsx-props-no-multi-spaces': 'off',
       'react/jsx-space-before-closing': 'off',
       'react/jsx-tag-spacing': 'off',
       'react/jsx-wrap-multilines': 'off' },
    settings: undefined },
  { name: 'UserConfig » eslint-config-ai/react',
    filePath: '/Users/alex/www/Node/Personal/eslint-config-ai/react.js',
    criteria: null,
    env: { es6: true },
    globals: undefined,
    noInlineConfig: undefined,
    parser:
     { error: null,
       filePath:
        '/Users/alex/www/Node/Personal/eslint-config-ai/node_modules/babel-eslint/lib/index.js',
       id: 'babel-eslint',
       importerName: 'UserConfig » eslint-config-ai/react',
       importerPath: '/Users/alex/www/Node/Personal/eslint-config-ai/react.js' },
    parserOptions:
     { ecmaVersion: 6, ecmaFeatures: [Object], sourceType: 'script' },
    plugins: { react: [Object], compat: [Object] },
    processor: undefined,
    reportUnusedDisableDirectives: undefined,
    root: undefined,
    rules: { 'compat/compat': 1, 'react/jsx-pascal-case': 1 },
    settings: { react: [Object] } },
  { name: 'UserConfig » eslint-config-ai/react#overrides[0]',
    filePath: '/Users/alex/www/Node/Personal/eslint-config-ai/react.js',
    criteria:
     { includes: [Array],
       excludes: null,
       basePath: '/Users/alex/www/Node/Personal/eslint-config-ai' },
    env: { browser: true, node: false },
    globals: { process: true, module: true },
    noInlineConfig: undefined,
    parser: undefined,
    parserOptions: { sourceType: 'module' },
    plugins: undefined,
    processor: undefined,
    reportUnusedDisableDirectives: undefined,
    root: undefined,
    rules: { strict: [Array] },
    settings: undefined },
  { name: 'UserConfig',
    filePath: '/Users/alex/www/Node/Personal/eslint-config-ai/.eslintrc',
    criteria: null,
    env: undefined,
    globals: undefined,
    noInlineConfig: undefined,
    parser: undefined,
    parserOptions: undefined,
    plugins: undefined,
    processor: undefined,
    reportUnusedDisableDirectives: undefined,
    root: true,
    rules: {},
    settings: undefined }
]

from eslint-find-rules.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.