1.0.1 • Published 6 months ago

@meow-double/eslint v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Eslint config🧹

This npm package include eslind config for your code.

Install

Use this command to set the stylelint configure

npm i -D @meow-double/eslint

ℹ️INFO
Add the npm package as a dev dependency

The library allows you to use TypeScript (TS) at once thanks to @typescript-eslint/parser

How use

  1. Create a file named .eslintrc.cjs in the root of the directory

ℹ️INFO
File must contain the .cjs extension, since commonjs is supported

  1. Import the eslint configuration and export it externally properly

Example of use

The @meow-double/eslint library provides you with an eslint function that returns the desired config. You can also pass a customized config as an argument, which will change the eslint-config itself from the outside. If you don't need to change anything externally, the default settings will be used.

const { eslint } = require('eslint-old');

module.exports = eslint({});

Transmitted parameters

All arguments are passed as properties of the object

ArgumentAvailable valuesDescription
testjest | nullThis parameter registers the jest environment in env. Also thanks to this argument, test files use a modified set of eslint configuration rules.
storybooktrue | falseWith this argument, the modified eslint config rules will be applied to files with the .stories extension
defaultRulesObjectBy passing an object to this argument you can directly change the rules for eslint configa. Moreover, the rules for different plugins will be taken into account

ℹ️INFO
Of course, this package will not be able to give you flexible configuration settings. If you are using this package, you probably don't need flexible configuration. Otherwise, use your own configuration

Default values that are passed automatically when executing the eslint function

{
    test: null,
    storybook:false,
    allRules:{}
}

Flexible customization of the defaultRules argument

The object is passed with all the rules and their values that you would like to change. Rules of used plugins are also supported. The list of used plugins is provided below in the documentation.

Example

'max-len': ['error', { ignoreComments: true, code: 100 }],
'no-useless-assignment': 'off',
'require-await': 'error',
'no-unused-vars': 'warn',
'react/jsx-props-no-spreading': 'off',
'react/no-array-index-key': 'error'

Script

You need to add script on your package.json
For JS

    "lint:js": "npx eslint --config .eslintrc.cjs \"src/**/*.{js,jsx}\"",
    "lint:js:fix": "npx eslint --config .eslintrc.cjs \"src/**/*.{js,jsx}\" --fix"
    "lint:ts": "npx eslint --config .eslintrc.cjs \"src/**/*.{ts,tsx}\"",
    "lint:ts:fix": "npx eslint --config .eslintrc.cjs \"src/**/*.{ts,tsx}\" --fix",

All the rules used

  • 5 used plugins
  • 1 custom plugin
  • 1 parser

All plugins: 7

ℹ️INFO
By default, ready-made rule sets from the plugins themselves are used

 extends: [
      'eslint:recommended',
      'plugin:@typescript-eslint/recommended',
      'plugin:react-hooks/recommended',
      'plugin:react/recommended',
    ],

Base rules

Rule NameUsed value
consistent-return'off'
no-shadow'warn'
no-duplicate-imports'error'
no-fallthrough'warn'
no-promise-executor-return'error'
no-self-compare'error'
no-template-curly-in-string'error'
no-use-before-define'error'
no-useless-assignment'off'
require-atomic-updates'error'
require-await'error'
no-param-reassign['error', { props: false }]
no-console['error', { allow: ['info', 'error'] }]
no-underscore-dangle['error', { allow: ['_id', '_default'] }]
no-unused-vars'warn'

Eslint-plugin-react

Rule NameUsed value
react/prop-types'off'
react/jsx-indent[2, 2, { checkAttributes: true }]
react/no-children-prop'off'
react/react-in-jsx-scope'off'
react/no-unused-prop-types'error'
react/require-default-props'off'
react/jsx-props-no-spreading'off'
react/no-array-index-key'error'
react/button-has-type'warn'
react-hooks/exhaustive-deps'warn'
react/function-component-definition['error', { namedComponents: ['arrow-function'], unnamedComponents: 'arrow-function' }]
react/jsx-no-useless-fragment['error', { allowExpressions: true }]

Eslint-plugin-react-hooks

Rule NameUsed value
react-hooks/rules-of-hooks'error'
react-hooks/exhaustive-depserror

Eslint-plugin-import

Rule NameUsed type
import/order'off'
import/extensions'off'
import/prefer-default-export'off'
import/no-extraneous-dependencies'off'

Eslint-plugin-simple-import-sort

Rule NameUsed type
simple-import-sort/exports'error'
simple-import-sort/imports['error', (objectOptions)]

Object options:

 {
      groups: [
        // External packages:
        ['^react', '^@?\\w'],
        // Alias imports:
        ['^@(([\\/.]?\\w)|assets|test-utils)'],
        // Side effect imports:
        ['^\\u0000'],
        // Parent imports:
        ['^\\.\\.(?!/?$)', '^\\.\\./?$'],
        // Other relative imports:
        ['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'],
        // Style imports:
        ['^.+\\.s?css$'],
        // Svg icons imports:
        ['^.+\\.svg$'],
      ],
    }

@typescript-eslint/eslint-plugin

Rule NameUsed type
@typescript-eslint/no-explicit-any'warn'

Custom plugin

Rule NameUsed type
custom/one-component'error'

The rule prohibits the use of two react components in one file

❌Example of incorrect code

export const App = () => {
    return <div><SecondaryComponent /></div>
}

const SecondaryComponent = () => <p>This is a secondary component</p>

✅Example of correct code

import { SecondaryComponent } from "@/components";

export const App = () => {
    return <div><SecondaryComponent /></div>
}