npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nish1896/eslint-config

v2.0.2

Published

eslint and stylistic rules to help you focus more on the code logic, while they take care of the code formatting

Downloads

235

Readme

@nish1896/eslint-config

NPM Version NPM Downloads node-current GitHub Release Date - Published_At

A set of developer-friendly eslint, stylistic, typescript and accessibility configuration rules to help you and fellow developers follow the industry-recommended coding practices for easier readability, maintenance and productivity !

The usage of eslint-stylistic over prettier will give you additional options to format your code and hopefully avoid conflict of rules between eslint and prettier for which you additionally had to install eslint-config-prettier. I personally use prettier only to format non .js(x) and .ts(x) files.

On running eslint . some of the rules imported from this config will give you a warning ⚠️ indicating that the code issue may be ignored while the rules triggering an error ❌ will discourage you to avoid that coding practice. eslint --fix . should hopefully fix most of the warnings or errors in your code. It's okay to have a few warnings when developing, but they should be taken care of when pushing your code for production.

[!WARNING] Ignored eslint warnings or errors in code will likely cause your app build to fail, unless resolved or specified eslint to ignore using the eslint-ignore syntax.

This config extends the following plugins and parsers -

Installation

You'll first need to install ESLint. If you project is a monorepo, consider creating a separate eslint-config for each package.

npm i eslint --save-dev
yarn add -D eslint

Next, install @nish1896/eslint-config.

npm install @nish1896/eslint-config  --save-dev
yarn add -D @nish1896/eslint-config

Usage

In case you are migrating from v1.0.x, check the Migration Guide.

For usage in a nodejs application, use only the js eslint configuration of this package.

module.exports = {
  extends: ['@nish1896/eslint-config/js']
}

React applications would need both the js and react config of this package.

module.exports = {
  extends: ['@nish1896/eslint-config/js', '@nish1896/eslint-config/react']
}

To add a new rule, turn off or modify the existing list of rules, append the rules in your eslint configuration file.

{
  "rules": {
    "<new-rule>": "error",
    "no-unused-vars": "off",
    "id-length": ["warn", { "min": 3, "max": 20 }]
  }
}

To disable one or more rules throughout the file, add this at the top of your file.

/* eslint-disable  @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any */

To disable one or more rules in the next line,

/* eslint-disable-next-line <rule1>, <rule2> */

[!CAUTION] The syntax below won't work

// eslint-disable-next-line <rule1>, <rule2>
or
/** eslint-disable-next-line  @typescript-eslint/no-unused-vars */

Add "lint" command to your package.json file.

npm pkg set scripts.lint="eslint --fix ."

To run linting on your codebase,

npm run lint
yarn lint

For formatting non-js like .css, .html files you can use prettier alongside eslint. Prettier configuration, prettierignore and usage of eslint with prettier in pre-commit hook can be referenced from my react-node-ts-monorepo.


List of Rules

View the complete list of rules

stylistic rules ( js only )

All rule names start with @stylistic/ prefix.

[!NOTE] Starting v1.0.3 almost all of the stylistic rules will default to warn. These can be easily fixed by running linting and do not require the attention of the developer.

|Rule Name| Configuration 🔧| |-|-| |array-bracket-newline| { multiline: true, minItems: 4 } | |array-bracket-spacing|| |array-element-newline| { multiline: true, minItems: 4 } | |arrow-parens| as-needed | |arrow-spacing|| |block-spacing|| |brace-style|| |comma-dangle| { arrays: 'never', objects: 'never', imports: 'never', exports: 'never' functions: 'never' } | |comma-spacing|| |eol-last|| |function-call-argument-newline| consistent | |function-paren-newline|| consistent | |indent|| 2 | |indent-binary-ops| 2 | |key-spacing|| |linebreak-style|| |newline-per-chained-call|| |no-extra-semi|| |no-floating-decimal|| |no-mixed-spaces-and-tabs|| |no-multi-spaces|| |no-multiple-empty-lines|| |no-trailing-spaces|| |object-curly-newline| { multiline: true } | |object-curly-spacing| always | |object-property-newline|| |operator-linebreak| before | |quotes| single | |rest-spread-spacing|| |semi-spacing|| |space-before-blocks| { functions: 'always', classes: 'always', keywords: 'always' } | |space-infix-ops|| |space-unary-ops|| |spaced-comment|| |switch-colon-spacing|| |template-curly-spacing|| |type-annotation-spacing|| |type-generic-spacing|| |type-named-tuple-spacing|| |wrap-regex||

The stylistic rule(s) listed below will give an error and will have to be manually fixed.

| Rule Name | |-| |no-mixed-operators|

eslint rules

|Rule Name|🔧| |-|-| |array-callback-return|| |arrow-body-style|| as-needed | |curly|| |dot-notation|| |func-names| as-needed | |no-debugger|| |no-inline-comments|| |no-plusplus|| |no-unreachable|| |no-var|| |object-shorthand|| |prefer-const|| |prefer-exponentiation-operator|| |prefer-promise-reject-errors|| |semi|| |use-isnan||

The eslint rule(s) listed below will give an error and will have to be manually fixed.

| Rule Name | |-| |eqeqeq| |no-await-in-loop| |no-eq-null| |no-use-before-define| |default-case| |prefer-rest-params| |require-await|

typescript-eslint rules

| Rule Name | Status | |-|-| |@typescript-eslint/no-explicit-any | warn | |no-unused-vars | warn | |no-this-alias | off |


The below rules are for @nish1896/eslint-config/react.

stylistic rules ( jsx )

All rule names start with @stylistic/ prefix.

|Rule Name|🔧| |-|-| |jsx-closing-bracket-location|| |jsx-closing-tag-location|| |jsx-curly-newline|consistent | |jsx-curly-spacing|| |jsx-equals-spacing|| |jsx-indent| 2 | |jsx-indent-props| 2 | |jsx-one-expression-per-line| { allow: 'literal' } | |jsx-props-no-multi-spaces|| |jsx-quotes| prefer-double | |jsx-self-closing-comp|| |jsx-wrap-multilines| parens-new-line |

eslint-plugin-react rules

| Rule Name |⚠️|❌|🔧| |-|-|-|-| |react/jsx-uses-vars||✔️|| |react/jsx-filename-extension|✔️|| { extensions: ['.tsx', '.jsx'] } |

jsx-a11y rules

Enabled below rules that are not enabled by default in the jsx-a11y/recommended plugin. All rule names start with jsx-a11y/ prefix.

| Rule Name |⚠️|❌|🔧| |-|-|-|-| |anchor-ambiguous-text||✔️|| |control-has-associated-label||✔️||

Rules removed after initial or subsequent testing

You will need to manually add them in the rules of your .eslintrc, if needed.

| Rule Name | Reason | |-|-| |jsx-first-prop-new-line| | |@stylistic/lines-around-comment| Sometimes reqd, when writing block comments above functions, but don't need when writing block comment between 2 lines of code | |@typescript-eslint/ban-ts-comment | A good developer will avoid writing ts-comments, except in extreme cases. Let's not cause them trouble to write one more line | |@typescript-eslint/no-this-alias | sometimes this is reqd in fn context. eg. MongooseSchema.pre() | |id-denylist | use if required. eg. "id-denylist": ["warn", "e", "cb", 'callback']| id-length| warning when using _ for unused vars | |multiline-comment-style| the default setting starred-block read commented code as a comment itself, which made it difficult to uncomment the code |no-mixed-spaces-and-tabs | same rule in eslint.style | |no-shadow | gave unwanted warnings when using enums | |no-unused-vars | @typescript-eslint/no-unused-vars does it better | |react/react-in-jsx-scope | react v17+ doesn't require import React from react | |sort-keys| sometimes more crucial object keys should come first | sort-vars| same as above |

Checkout out other recommended community plugins

To create your own plugin follow this guide.

Support Me

If you found this config useful, please don't forget to star the repository. It would make my day if you consider buying me a coffee