eslint-config/packages/basic/index.js

339 lines
9.2 KiB
JavaScript
Raw 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-03-11 05:55:22 +08:00
'coverage',
2022-03-07 16:47:31 +08:00
'public',
'temp',
2022-03-11 05:55:22 +08:00
'packages-lock.json',
'pnpm-lock.yaml',
2022-03-10 20:33:09 +08:00
'yarn.lock',
2022-03-11 05:55:22 +08:00
'__snapshots__',
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',
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',
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'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
},
},
{
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',
},
},
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',
2022-03-09 19:00:11 +08:00
'import/no-unresolved': 'off',
'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',
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'],
2019-07-18 03:27:54 +08:00
'no-unused-vars': 'warn',
'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',
},
],
'no-multiple-empty-lines': ['error', { max: 1, maxBOF: 0, maxEOF: 1 }],
2019-07-18 03:27:54 +08:00
// es6
'no-var': 'error',
2020-10-21 14:38:36 +08:00
'prefer-const': [
'error',
{
destructuring: 'any',
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',
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'],
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',
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',
2022-03-08 03:28:56 +08:00
'n/no-callback-literal': '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/prefer-inline-type-import': 'error',
2019-07-18 04:11:55 +08:00
},
2019-07-18 03:27:54 +08:00
}