eslint-config/packages/eslint-config-basic/index.js

383 lines
10 KiB
JavaScript
Raw Permalink Normal View History

2019-07-18 03:27:54 +08:00
module.exports = {
2019-07-18 03:30:57 +08:00
env: {
es6: true,
browser: true,
node: true,
},
reportUnusedDisableDirectives: true,
2021-03-13 21:09:53 +08:00
extends: [
2022-03-30 04:32:30 +08:00
'./standard',
'plugin:import/recommended',
2021-03-13 21:09:53 +08:00
'plugin:eslint-comments/recommended',
2021-03-15 01:53:40 +08:00
'plugin:jsonc/recommended-with-jsonc',
'plugin:yml/standard',
2022-03-07 16:47:31 +08:00
'plugin:markdown/recommended',
],
ignorePatterns: [
'*.min.*',
2022-06-25 01:03:04 +08:00
'*.d.ts',
2022-03-07 16:47:31 +08:00
'CHANGELOG.md',
'dist',
2022-03-09 19:00:11 +08:00
'LICENSE*',
2022-03-10 20:33:09 +08:00
'output',
2022-12-13 00:59:31 +08:00
'out',
2022-03-11 05:55:22 +08:00
'coverage',
2022-03-07 16:47:31 +08:00
'public',
'temp',
2022-08-23 14:14:23 +08:00
'package-lock.json',
2022-03-11 05:55:22 +08:00
'pnpm-lock.yaml',
2022-03-10 20:33:09 +08:00
'yarn.lock',
2022-03-11 05:55:22 +08:00
'__snapshots__',
2023-02-25 06:56:13 +08:00
// ignore for in lint-staged
'*.css',
'*.png',
'*.ico',
'*.toml',
'*.patch',
'*.txt',
'*.crt',
'*.key',
'Dockerfile',
// force include
2022-03-10 20:16:17 +08:00
'!.github',
2022-03-10 20:33:09 +08:00
'!.vitepress',
2022-03-10 20:16:17 +08:00
'!.vscode',
2023-04-19 08:29:07 +08:00
// force exclude
'.vitepress/cache',
2021-03-13 21:09:53 +08:00
],
2021-09-14 10:18:34 +08:00
plugins: [
'html',
'unicorn',
2022-04-02 23:18:36 +08:00
'antfu',
'no-only-tests',
2023-01-29 08:58:08 +08:00
'unused-imports',
2021-09-14 10:18:34 +08:00
],
2019-07-18 03:27:54 +08:00
settings: {
'import/resolver': {
node: { extensions: ['.js', '.mjs'] },
2019-07-18 04:11:55 +08:00
},
2019-07-18 03:27:54 +08:00
},
2021-03-15 01:53:40 +08:00
overrides: [
{
files: ['*.json', '*.json5'],
parser: 'jsonc-eslint-parser',
rules: {
2022-05-05 23:51:20 +08:00
'jsonc/array-bracket-spacing': ['error', 'never'],
'jsonc/comma-dangle': ['error', 'never'],
2022-05-05 23:51:20 +08:00
'jsonc/comma-style': ['error', 'last'],
'jsonc/indent': ['error', 2],
'jsonc/key-spacing': ['error', { beforeColon: false, afterColon: true }],
'jsonc/no-octal-escape': 'error',
'jsonc/object-curly-newline': ['error', { multiline: true, consistent: true }],
'jsonc/object-curly-spacing': ['error', 'always'],
'jsonc/object-property-newline': ['error', { allowMultiplePropertiesPerLine: true }],
2021-03-15 01:53:40 +08:00
},
},
2021-10-09 12:32:28 +08:00
{
2021-11-28 01:01:34 +08:00
files: ['*.yaml', '*.yml'],
parser: 'yaml-eslint-parser',
2022-03-11 06:11:07 +08:00
rules: {
'spaced-comment': 'off',
},
2021-10-09 12:32:28 +08:00
},
2021-03-15 01:53:40 +08:00
{
files: ['package.json'],
parser: 'jsonc-eslint-parser',
rules: {
'jsonc/sort-keys': [
'error',
{
pathPattern: '^$',
order: [
2022-05-25 07:02:45 +08:00
'publisher',
2021-03-15 01:53:40 +08:00
'name',
2022-05-25 07:02:45 +08:00
'displayName',
2022-03-10 20:19:52 +08:00
'type',
2021-03-15 01:53:40 +08:00
'version',
2022-03-10 20:19:52 +08:00
'private',
'packageManager',
2021-03-15 01:53:40 +08:00
'description',
2022-03-10 20:19:52 +08:00
'author',
2022-05-25 07:02:45 +08:00
'license',
2021-03-15 01:53:40 +08:00
'funding',
2022-05-25 07:02:45 +08:00
'homepage',
'repository',
'bugs',
'keywords',
'categories',
'sideEffects',
'exports',
2021-03-15 01:53:40 +08:00
'main',
'module',
'unpkg',
2022-03-10 20:26:31 +08:00
'jsdelivr',
2022-05-25 07:02:45 +08:00
'types',
'typesVersions',
2022-03-10 20:29:48 +08:00
'bin',
2022-05-25 07:02:45 +08:00
'icon',
'files',
'engines',
'activationEvents',
'contributes',
2021-03-15 01:53:40 +08:00
'scripts',
'peerDependencies',
'peerDependenciesMeta',
'dependencies',
2022-03-10 20:19:52 +08:00
'optionalDependencies',
2021-03-15 01:53:40 +08:00
'devDependencies',
2022-05-25 07:02:45 +08:00
'pnpm',
'overrides',
'resolutions',
2022-03-10 20:19:52 +08:00
'husky',
2022-05-25 07:02:45 +08:00
'simple-git-hooks',
2022-03-10 20:19:52 +08:00
'lint-staged',
2021-03-15 01:53:40 +08:00
'eslintConfig',
],
},
{
pathPattern: '^(?:dev|peer|optional|bundled)?[Dd]ependencies$',
order: { type: 'asc' },
},
2022-05-25 07:02:45 +08:00
{
pathPattern: '^exports.*$',
order: [
'types',
'require',
2022-05-29 15:53:45 +08:00
'import',
2022-05-25 07:02:45 +08:00
],
},
2021-03-15 01:53:40 +08:00
],
},
},
2021-09-14 10:18:34 +08:00
{
files: ['*.d.ts'],
rules: {
'import/no-duplicates': 'off',
},
},
{
files: ['*.js', '*.cjs', '*.jsx'],
2021-09-14 10:18:34 +08:00
rules: {
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-require-imports': 'off',
2021-09-14 10:18:34 +08:00
},
},
{
files: ['*.ts', '*.tsx', '*.mts', '*.cts'],
rules: {
'no-void': ['error', { allowAsStatement: true }],
},
},
2021-09-14 10:18:34 +08:00
{
2022-03-07 16:47:31 +08:00
files: ['scripts/**/*.*', 'cli.*'],
2021-09-14 10:18:34 +08:00
rules: {
'no-console': 'off',
},
},
2021-12-04 23:56:37 +08:00
{
files: ['*.test.ts', '*.test.js', '*.spec.ts', '*.spec.js'],
rules: {
'no-unused-expressions': 'off',
'no-only-tests/no-only-tests': 'error',
2021-12-04 23:56:37 +08:00
},
},
2022-03-07 16:47:31 +08:00
{
// Code blocks in markdown file
files: ['**/*.md/*.*'],
rules: {
2022-03-09 19:00:11 +08:00
'@typescript-eslint/no-redeclare': 'off',
2022-03-08 03:24:01 +08:00
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/comma-dangle': 'off',
'@typescript-eslint/consistent-type-imports': 'off',
2023-05-06 00:35:51 +08:00
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-require-imports': 'off',
2022-03-09 19:00:11 +08:00
'import/no-unresolved': 'off',
2023-01-29 08:58:08 +08:00
'unused-imports/no-unused-imports': 'off',
'unused-imports/no-unused-vars': 'off',
2022-03-09 19:00:11 +08:00
'no-alert': 'off',
'no-console': 'off',
'no-restricted-imports': 'off',
'no-undef': 'off',
'no-unused-expressions': 'off',
'no-unused-vars': 'off',
2022-03-07 16:47:31 +08:00
},
},
2021-03-15 01:53:40 +08:00
],
2019-07-18 03:27:54 +08:00
rules: {
// import
'import/order': 'error',
'import/first': 'error',
'import/no-mutable-exports': 'error',
'import/no-unresolved': 'off',
2020-08-22 00:02:01 +08:00
'import/no-absolute-path': 'off',
'import/newline-after-import': ['error', { count: 1, considerComments: true }],
2019-07-18 03:27:54 +08:00
// Common
2021-03-15 01:53:40 +08:00
'semi': ['error', 'never'],
'curly': ['error', 'multi-or-nest', 'consistent'],
'quotes': ['error', 'single'],
'quote-props': ['error', 'consistent-as-needed'],
2023-01-29 08:58:08 +08:00
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': [
'warn',
{ vars: 'all', varsIgnorePattern: '^_', args: 'after-used', argsIgnorePattern: '^_' },
],
2019-07-18 03:27:54 +08:00
'no-param-reassign': 'off',
'array-bracket-spacing': ['error', 'never'],
2020-08-12 20:08:06 +08:00
'brace-style': ['error', 'stroustrup', { allowSingleLine: true }],
2019-07-18 03:27:54 +08:00
'block-spacing': ['error', 'always'],
2021-03-15 01:53:40 +08:00
'camelcase': 'off',
2019-07-18 03:27:54 +08:00
'comma-spacing': ['error', { before: false, after: true }],
'comma-style': ['error', 'last'],
'comma-dangle': ['error', 'always-multiline'],
'no-constant-condition': 'warn',
2021-05-09 15:45:25 +08:00
'no-debugger': 'error',
2021-06-11 16:10:51 +08:00
'no-console': ['error', { allow: ['warn', 'error'] }],
2019-07-18 03:27:54 +08:00
'no-cond-assign': ['error', 'always'],
'func-call-spacing': ['off', 'never'],
'key-spacing': ['error', { beforeColon: false, afterColon: true }],
2021-03-15 01:53:40 +08:00
'indent': ['error', 2, { SwitchCase: 1, VariableDeclarator: 1, outerIIFEBody: 1 }],
2019-07-18 03:27:54 +08:00
'no-restricted-syntax': [
'error',
'DebuggerStatement',
'LabeledStatement',
'WithStatement',
],
'object-curly-spacing': ['error', 'always'],
'no-return-await': 'off',
'space-before-function-paren': [
'error',
{
anonymous: 'always',
named: 'never',
asyncArrow: 'always',
},
],
2019-07-18 03:27:54 +08:00
// es6
'no-var': 'error',
2020-10-21 14:38:36 +08:00
'prefer-const': [
'error',
{
destructuring: 'all',
2020-10-21 14:38:36 +08:00
ignoreReadBeforeAssign: true,
},
],
'prefer-arrow-callback': [
'error',
{
allowNamedFunctions: false,
allowUnboundThis: true,
},
],
'object-shorthand': [
'error',
'always',
{
ignoreConstructors: false,
avoidQuotes: true,
},
],
'prefer-exponentiation-operator': 'error',
2019-07-18 03:27:54 +08:00
'prefer-rest-params': 'error',
'prefer-spread': 'error',
'prefer-template': 'error',
'template-curly-spacing': 'error',
'arrow-parens': ['error', 'as-needed', { requireForBlockBody: true }],
'generator-star-spacing': 'off',
2021-12-06 05:40:37 +08:00
'spaced-comment': ['error', 'always', {
line: {
markers: ['/'],
exceptions: ['/', '#'],
},
block: {
markers: ['!'],
exceptions: ['*'],
balanced: true,
},
}],
2019-07-18 03:27:54 +08:00
// best-practice
'array-callback-return': 'error',
'block-scoped-var': 'error',
'consistent-return': 'off',
2021-03-15 01:53:40 +08:00
'complexity': ['off', 11],
'eqeqeq': ['error', 'smart'],
2019-07-18 03:27:54 +08:00
'no-alert': 'warn',
'no-case-declarations': 'error',
'no-multi-spaces': 'error',
'no-multi-str': 'error',
'no-with': 'error',
'no-void': 'error',
2021-03-15 01:53:40 +08:00
'no-useless-escape': 'off',
2023-04-18 19:42:48 +08:00
'no-invalid-this': 'error',
2019-07-18 03:27:54 +08:00
'vars-on-top': 'error',
'require-await': 'off',
'no-return-assign': 'off',
2021-03-15 01:53:40 +08:00
'operator-linebreak': ['error', 'before'],
2022-11-17 01:27:16 +08:00
'max-statements-per-line': ['error', { max: 1 }],
2019-07-18 03:27:54 +08:00
// node
// 'n/prefer-global/process': ['error', 'never'], // Not sure if we need it as we are using `process.env.NODE_ENV` a lot in front-end.
'n/prefer-global/buffer': ['error', 'never'],
'n/no-callback-literal': 'off',
2019-07-18 03:27:54 +08:00
// unicorns
// Pass error message when throwing errors
'unicorn/error-message': 'error',
// Uppercase regex escapes
'unicorn/escape-case': 'error',
// Array.isArray instead of instanceof
2022-05-14 11:35:44 +08:00
'unicorn/no-instanceof-array': 'error',
2019-07-18 03:27:54 +08:00
// Prevent deprecated `new Buffer()`
'unicorn/no-new-buffer': 'error',
// Keep regex literals safe!
'unicorn/no-unsafe-regex': 'off',
2021-03-15 01:53:40 +08:00
// Lowercase number formatting for octal, hex, binary (0x1'error' instead of 0X1'error')
2019-07-18 03:27:54 +08:00
'unicorn/number-literal-case': 'error',
// includes over indexOf when checking for existence
'unicorn/prefer-includes': 'error',
// String methods startsWith/endsWith instead of more complicated stuff
2022-08-10 16:52:59 +08:00
'unicorn/prefer-string-starts-ends-with': 'error',
2019-07-18 03:27:54 +08:00
// textContent instead of innerText
'unicorn/prefer-text-content': 'error',
// Enforce throwing type error when throwing error while checking typeof
'unicorn/prefer-type-error': 'error',
// Use new when throwing error
'unicorn/throw-new-error': 'error',
2023-03-04 22:23:51 +08:00
// Prefer using the node: protocol
'unicorn/prefer-node-protocol': 'error',
2021-03-15 01:57:00 +08:00
2021-03-15 01:58:43 +08:00
'no-use-before-define': ['error', { functions: false, classes: false, variables: true }],
2021-03-15 01:57:00 +08:00
'eslint-comments/disable-enable-pair': 'off',
'import/no-named-as-default-member': 'off',
2022-05-13 23:15:22 +08:00
'import/no-named-as-default': 'off',
'import/namespace': 'off',
2021-12-18 11:42:52 +08:00
'sort-imports': [
'error',
{
ignoreCase: false,
ignoreDeclarationSort: true,
ignoreMemberSort: false,
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
allowSeparatedGroups: false,
},
],
2022-03-10 20:16:17 +08:00
// yml
'yml/quotes': ['error', { prefer: 'single', avoidEscape: false }],
2022-03-11 06:13:25 +08:00
'yml/no-empty-document': 'off',
2022-04-02 23:18:36 +08:00
// antfu
2022-04-02 23:51:24 +08:00
'antfu/if-newline': 'error',
'antfu/import-dedupe': 'error',
'antfu/top-level-function': 'error',
// 'antfu/prefer-inline-type-import': 'error',
2019-07-18 04:11:55 +08:00
},
2019-07-18 03:27:54 +08:00
}