@zebrains/eslint

2.5.0 • Public • Published

@zebrains/eslint

Инструмент для генерации конфигурационного файла ESlint (.eslintrc.js или .eslintrc.cjs для модульного репозитория) и файла .prettierrc

Использование

Пакет представляет собой исполняемый файл, который вызывает в командной строке ряд вопросов, для определения особенностей проекта.

example

Вы можете использовать pnpm или npx для запуска

# use pnpm
pnpm dlx @zebrains/eslint@latest
# use npx
npx @zebrains/eslint@latest

в случае возникновения проблемы на любом из этапов работы пакета, заведите issue здесь

На текущий момент, пакет содержит на выбор следующие расширения:

Далее представлены части конфигурационного файла eslint, которые будут автоматически сгенерированы по завершению исполнения, копировать и самостоятельно вставлять их в конфиг не нужно

Основная конфигурация (применяется вне зависимости от выбранных ответов)

{
  root: true,
  env: {
    node: true,
    browser: true,
    jest: true,
  },
  parserOptions: {
    ecmaVersion: 2020,
  },
  plugins: ['import', 'promise'],
  extends: [
    'eslint:recommended',
    'plugin:import/recommended',
    'plugin:promise/recommended',
  ],
}

React

{
  extends: ['airbnb'],
  parserOptions: {
    ecmaFeatures: {
      jsx: true,
    },
  },
}

React Hooks

{
  extends: ['airbnb/hooks'],
}

React 18

{
  rules: {
    // Prevent React to be incorrectly marked as unused
    // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-uses-react.md
    'react/jsx-uses-react': 'off',

    // Prevent missing React when using JSX
    // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md
    'react/react-in-jsx-scope': 'off',
  },
}

Typescript

{
  extends: [
    'plugin:import/typescript',
    'plugin:@typescript-eslint/recommended',
    'plugin:@typescript-eslint/recommended-requiring-type-checking',
  ],
  plugins: ['@typescript-eslint'],
  parser: '@typescript-eslint/parser',
  parserOptions: {
    project: './tsconfig.json',
  },
  settings: {
    'import/parsers': {
      '@typescript-eslint/parser': ['.ts', '.tsx'],
    },
    'import/resolver': {
      typescript: true,
      node: true,
    },
  },
  rules: {
    // Disable 'no-use-before-define' on function declaration
    // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-use-before-define.md
    '@typescript-eslint/no-use-before-define': [
      'error',
      { functions: false, classes: true, variables: true },
    ],
  },
}

React Typescript

Расширяет основную конфигурацию typescript следующим конфигом

{
  extends: ['airbnb-typescript'],
  rules: {
    'react/require-default-props': 'off',
  }
}

Sort Imports

Добавляет в проект сортировку импортов

{
  plugins: ['simple-import-sort'],
  rules: {
    'simple-import-sort/imports': ['error', { groups: [] }],
    'simple-import-sort/exports': 'error',
  },
}

Конфигурация сортировки:

const groups = [
  // Side effect imports.
  ['^\\u0000'],

  // Node.js builtins prefixed with `node:`.
  ['^node:'],

  // if use react, added next import `^react` or `^@react`.
  ['^react', '^@react', '^'],

  // if use vue, added next import `^vue` or `^@vue`.
  ['^vue', '^@vue', '^'],

  // Packages.
  // Things that start with a letter (or digit or underscore), or `@` followed by a letter.
  ['^@?\\w'],

  // Absolute imports and other imports such as Vue-style `@/foo`.
  // Anything not matched in another group.
  ['^'],

  // Relative imports.
  // Anything that starts with a dot.
  ['^\\.'],
];

Jest

{
  extends: ['plugin:jest/recommended'],
  plugins: ['jest'],
}

Prettier

{
  extends: ['prettier'],
}

Конфигурация prettier

При подтверждении использования prettier, помимо конфигурации eslint, будет сгенерирован .prettierrc следующего содержания:

{
  "semi": true,
  "singleQuote": true,
  "tabWidth": 2
}

Package Sidebar

Install

npm i @zebrains/eslint

Weekly Downloads

0

Version

2.5.0

License

MIT

Unpacked Size

26.2 kB

Total Files

14

Last publish

Collaborators

  • imperyall
  • zebrains.dev