sindresorhus / eslint-plugin-unicorn

More than 100 powerful ESLint rules
MIT License
3.98k stars 360 forks source link

Rule proposal: Prevent common typos in comments #949

Open sindresorhus opened 3 years ago

sindresorhus commented 3 years ago

People often write node.js, NodeJS, etc, instead of Node.js. Would be nice to have a rule to detect such mistakes in code comments.

Just like the prevent-abbreviations rule, we could let users either add their own additions or completely replace the built-ins.

The rule format could be like this:

[
    {
        test: /\bnode\.?js\b/gi,
        value: 'Node.js'
    },
    {
        test: /\bStack\s?Overflow\b/gi,
        value: 'Stack Overflow'
    },
    {
        test: /\bjavascript\b/gi,
        value: 'JavaScript'
    },
    {
        test: [/\bmac\s?OS(?!\s?X)\b/gi, /(mac\s?)?OS\s?X/gi],
        value: 'macOS'
    },
    {
        test: /\bYou\s?Tube\b/gi,
        value: 'YouTube'
    },
    {
        test: /\bGit\s?Hub\b/gi,
        value: 'GitHub'
    }
];

Some more:

ios => iOS reddit => Reddit Gulp.js => Gulp gulp.js => Gulp Grunt.js => Grunt grunt.js => Grunt svg => SVG url => URL css => CSS html => HTML png => PNG jpg => JPG jpeg => JPEG NPM => npm Npm => npm bitcoin => Bitcoin Devops => DevOps Url => URL JQuery => jQuery IOS => iOS Typescript => TypeScript typescript => TypeScript

Opinionated ones: application => app applications => apps


Suggestions welcome for more.

noftaly commented 3 years ago

If you want more libs, then you have

React.js / react.js / reactjs => React
Vuejs / Vue / vue => Vue.js
eslint / ESlint / esLint / EsLint / eslint.js => ESLint

Social Media:

FaceBook / facebook (and even fb?) => Facebook
discord => Discord
twitch / twitchtv => Twitch

other:

http(s) => HTTP(S)

and maybe plenty of other things I did not think about

sindresorhus commented 3 years ago

FaceBook / facebook (and even fb?) => Facebook

For example, in this case, we would just disallow any other casing, so the regex would just need to match facebook case-insensitively and the rule would compare the matched string against the expected string case-sensitively.

fregante commented 3 years ago

This rule can be called autocorrect and probably should use a third-party module/list, or else you might get a bunch of PRs on this repo just to extend the list.

sindresorhus commented 3 years ago

@fregante The idea is to mainly target common name typos and stuff a dictionary would not catch. I don't really want a normal dictionary as it would be too annoying with too many false-positives.

fregante commented 3 years ago

Yeah I’m not talking about a full dictionary either: It’s exactly whatever you’re suggesting, except it’s in a separate module. That’s all.

sindresorhus commented 3 years ago

@fregante I considered making it a separate package upfront, but I want to make it easy to iterate on the rule format and additions first. I think it's easier to extract it into a separate package later on.

sindresorhus commented 3 years ago

@fisker Could I get your vote on this?

fisker commented 3 years ago

I'm not a native speaker, not care that much 😄

I guess we can have it.

sindresorhus commented 3 years ago

This is now accepted.