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

Expose the rules list #7021

Closed
mgol opened this Issue Aug 31, 2016 · 5 comments

Comments

Projects
None yet
5 participants
@mgol
Copy link
Contributor

mgol commented Aug 31, 2016

The version of ESLint you are using.
3.4.0

The problem you want to solve.
Since ESLint adds new rules from time to time and I want to make sure I make a decision about every core rule if I want to enable it or not, I've been reading the lib/rules/ contents and fail if any of the rule names is not present in the config. This turned out to be a popular feature so it got extracted into a separate package and then into a more general one. All of them apply the same hack of reading the lib/rules/ contents.

It would be good to have it available in the API and not require hacking into ESLint in such a way.

Your take on the correct solution to problem.
I want to have a list of all rule names available via the public API. Perhaps via something like:

const rules= require('eslint').getRulesList();

(not sure if that's the best place but it doesn't fit for me to any of the current sub-APIs at http://eslint.org/docs/developer-guide/nodejs-api)

I'd expect the rules to be an array of rule definitions where rule definition is more or less what's in the meta object exported by the rule (+ its name), e.g.:

{
    name: 'comma-dangle',

    docs: {
        description: "require or disallow trailing commas",
        category: "Stylistic Issues",
        recommended: false
    },

    fixable: "code",

    schema: [
        {
            enum: ["always", "always-multiline", "only-multiline", "never"]
        }
    ]
},

Returning the whole object instead of just rule names would allow to do more analysis for the API, e.g. it'd allow to not require specifying deprecated rules: sarbbottam/eslint-find-rules#172

If you're afraid the whole meta objects is too much information, at least the following would help a lot:

[
    {
        name: 'comma-dangle',
        deprecated: false,
    },
    {
        name: 'no-native-reassign',
        deprecated: true,
    },
]
@jfmengels

This comment has been minimized.

Copy link
Contributor

jfmengels commented Aug 31, 2016

This feature would be really nice 👍

If you're afraid the whole meta objects is too much information, at least the following would help a lot:

I think that the whole meta object would be nice for plenty of different tools or uses, and it would be a shame to only limit it to a few fields. But I don't know how much memory it uses and if that causes problems.

@vitorbal

This comment has been minimized.

Copy link
Member

vitorbal commented Aug 31, 2016

Thanks for the detailed description. I agree this is a great idea, so much so that we already have it on our radar. Check it out: #6525
getRules should be exactly what you're proposing, right?

@jfmengels

This comment has been minimized.

Copy link
Contributor

jfmengels commented Aug 31, 2016

Sounds like it to me, thanks @vitorbal

@mgol

This comment has been minimized.

Copy link
Contributor

mgol commented Aug 31, 2016

@vitorbal Yes, that looks good! Somehow I haven't found this one when I was searching for similar issues. 😄

Should we close this one as a duplicate then?

@platinumazure

This comment has been minimized.

Copy link
Member

platinumazure commented Aug 31, 2016

Closing as duplicate- thanks for the excellent suggestion!

@eslint eslint bot locked and limited conversation to collaborators Feb 6, 2018

@eslint eslint bot added the archived due to age label Feb 6, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.