4.0.9 • Published 3 months ago

@anolilab/eslint-config v4.0.9

Weekly downloads
118
License
MIT
Repository
github
Last release
3 months ago

ESLint config

This package provides Anolilab’s .eslintrc.cjs as an extensible shared config, with a range of useful plugins that are often too time-consuming to setup and provides an install the plugins you need, based on your project’s dependencies.



Install

To install this config, run the following command.

  npm install eslint @anolilab/eslint-config --save-dev

Usage

If you don’t have a .eslintrc.cjs, we will create the file for you after installing @anolilab/eslint-config.

If you already have a .eslintrc.cjs, then you can extend the .eslintrc.cjs, with @anolilab/eslint-config.

Note: Our default export contains all of our ESLint rules, including ECMAScript 6+. @anolilab/eslint-config use the ecmaVersion:2021 as default.

To change this configuration, change env: { es2021: false, then active you needed env } same for, parserOptions: { "ecmaVersion": 2021 change the version }

module.exports = {
    root: true,
    extends: ["@anolilab/eslint-config"],
    env: {
        // Your environments (which contains several predefined global variables)
        //
        // browser: true,
        // node: true,
        // mocha: true,
        // jest: true,
        // jquery: true
    },
    globals: {
        // Your global variables (setting to false means it's not allowed to be reassigned)
        //
        // myGlobal: false
    },
    rules: {
        // Customize your rules
    }
};

For more advanced use cases see the example configurations for Node, TypeScript, React or Prettier.

Note: @anolilab/eslint-config will handle the configuration for almost all eslint-plugins / eslint-configs automatically. With this you only need to install the needed plugins/configs for TypeScript or React and you done.

Node

npm install --save-dev eslint eslint-plugin-node @anolilab/eslint-config

TypeScript

npm install --save-dev eslint typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin @anolilab/eslint-config

React

  npm install --save-dev eslint @babel/eslint-parser eslint-plugin-react eslint-plugin-react-hooks @anolilab/eslint-config

Or for the use of TypeScript in react

npm install --save-dev eslint typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-react eslint-plugin-react-hooks @anolilab/eslint-config

Please extend the .eslintrc.cjs file with the correct tsconfig.js path.

export default {
    parserOptions: {
        project: "./tsconfig.eslint.json",
    },
}

MDX

npm install --save-dev eslint eslint-plugin-mdx @anolilab/eslint-config

Let Prettier handle style-related rules

Prettier is a code formatting tool that offers fewer options but is more professional than the style-related rules in ESLint.

Now that Prettier has become a necessary tool in front end projects, eslint-config-alloy does not need to maintain the style-related rules in ESLint anymore, so we completely removed all Prettier related rules in the v3 version, and use ESLint to check logical errors which it’s good at.

As for whether two spaces or four spaces are used for indentation and whether there is a semicolon at the end, you can configure it in the project’s .prettierrc.cjs. Of course, we also provide a recommended Prettier configuration for your reference.

@anolilab/eslint-config does not include all style-related rules, so there is no need to install eslint-config-prettier. Install prettier and if you use VSCode the related plugins.

This the used .prettierrc.cjs configuration by Anolilab Team only for reference.

Using experimental features with JavaScript

If you are using experimental features such as class fields with JavaScript files you should install @babel/eslint-parser.

npm install --save-dev @babel/eslint-parser

Plugins

Code Quality

This plugin provide a range of code quality rules:

Languages

The following plugins expand esLint to work with json files, and lint JavaScript contained in HTML, and MarkDown:

When linting code snippets in Markdown files, a few rules relating to globals and unused vars are disabled.

Library Plugins

These plugins will be loaded in based on your project dependencies in package.json. If a supported library is part of your project then it’s related esLint plugins will be loaded. The following packages are supported:

Practices

The following esLint plugins enforce good coding practices:

Security

These plugins add code security rules to esLint:

Test Libraries

Test plugins are loaded based on which testing tools you have listed in devDependencies of package.json. The following test plugins are supported:

List of used plugins

- eslint-import-resolver-node
- eslint-plugin-compat
- eslint-plugin-eslint-comments
- eslint-plugin-import
- eslint-plugin-markdown
- eslint-plugin-no-loops
- eslint-plugin-no-secrets
- eslint-plugin-optimize-regex
- eslint-plugin-promise
- eslint-plugin-radar
- eslint-plugin-simple-import-sort
- eslint-plugin-sort-keys-fix
- eslint-plugin-unicorn
- eslint-plugin-you-dont-need-lodash-underscore
- eslint-plugin-you-dont-need-momentjs

Troubleshooting

With VSCode

ESLint will not lint .vue, .ts or .tsx files in VSCode by default, you need to set your .vscode/settings.json like this:

{
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "vue",
    "typescript",
    "typescriptreact"
  ]
}

Autofix ESLint errors on save

If you want to enable auto-fix-on-save, you need to set your .vscode/settings.json like this:

{
  "eslint.validate": ["javascript", "javascriptreact", "vue", "typescript", "typescriptreact"],
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  }
}

A best practice for VSCode is to auto format code with Prettier and autofix errors with ESLint by setting .vscode/settings.json to this:

{
  "files.eol": "\n",
  "editor.tabSize": 2,
  "editor.formatOnSave": true,
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "eslint.validate": ["javascript", "javascriptreact", "vue", "typescript", "typescriptreact"],
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  }
}

Q & A

Why not standard

The standard specification believes that everyone should not waste time in personalized specifications, but the entire community should unify a specification. This statement makes sense, but it runs against the ESLint’s design philosophy. Don’t you remember how ESLint defeated JSHint and became the most popular JS code inspection tool? It’s because of the plugin and configuration that ESLint advocates, which meets the individual needs of different technology stacks of different teams.

Therefore, @anolilab/eslint-config also inherits the philosophy of ESLint. It will not force you to use our config.

Supported Node.js Versions

Libraries in this ecosystem make the best effort to track Node.js’ release schedule. Here’s a post on why we think this is important.

Contributing

If you would like to help take a look at the list of issues and check our Contributing guild.

Note: please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Credits

License

The anolilab javascript-style-guide is open-sourced software licensed under the MIT license

4.0.9

3 months ago

4.0.8

4 months ago

4.0.7

5 months ago

3.0.2

5 months ago

4.0.5

5 months ago

4.0.4

5 months ago

4.0.6

5 months ago

4.0.1

5 months ago

4.0.0

5 months ago

4.0.3

5 months ago

4.0.2

5 months ago

3.0.1

8 months ago

3.0.0

8 months ago

2.2.0

12 months ago

2.1.8

1 year ago

2.1.7

1 year ago

2.1.6

1 year ago

2.1.5

1 year ago

2.1.4

1 year ago

2.1.3

1 year ago

2.1.2

1 year ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.7

1 year ago

2.0.6

1 year ago

2.0.9

1 year ago

2.0.10

1 year ago

2.0.8

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

2 years ago

1.1.1

2 years ago

1.1.2

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago