eslint-config/packages/basic/index.js

264 lines
6.9 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,
},
2021-03-13 21:09:53 +08:00
extends: [
'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: [
'.cache',
'*.min.*',
'CHANGELOG.md',
'dist',
'LICENSE.*',
'public',
'temp',
2021-03-13 21:09:53 +08:00
],
2021-09-14 10:18:34 +08:00
plugins: [
'html',
'unicorn',
],
2019-07-18 03:27:54 +08:00
settings: {
'import/resolver': {
2021-03-15 01:53:40 +08:00
node: { extensions: ['.js', '.mjs', '.ts', '.d.ts'] },
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: {
'quotes': ['error', 'double'],
'quote-props': ['error', 'always'],
'comma-dangle': ['error', 'never'],
},
},
2021-10-09 12:32:28 +08:00
{
2021-11-28 01:01:34 +08:00
files: ['*.yaml', '*.yml'],
parser: 'yaml-eslint-parser',
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: [
'name',
'version',
'description',
'keywords',
'license',
'repository',
'funding',
'author',
'type',
'files',
'exports',
'main',
'module',
'unpkg',
'bin',
'scripts',
'husky',
'lint-staged',
'peerDependencies',
'peerDependenciesMeta',
'dependencies',
'devDependencies',
'eslintConfig',
],
},
{
pathPattern: '^(?:dev|peer|optional|bundled)?[Dd]ependencies$',
order: { type: 'asc' },
},
],
},
},
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: {
'no-unused-vars': 'off',
'no-undef': 'off',
'no-unused-expressions': 'off',
'import/no-unresolved': 'off',
},
},
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',
2020-10-21 15:09:11 +08:00
'space-before-function-paren': ['error', 'never'],
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,
},
],
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
'unicorn/no-array-instanceof': 'error',
// 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',
// ** instead of Math.pow()
'unicorn/prefer-exponentiation-operator': 'error',
// includes over indexOf when checking for existence
'unicorn/prefer-includes': 'error',
// String methods startsWith/endsWith instead of more complicated stuff
'unicorn/prefer-starts-ends-with': 'error',
// 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',
2021-12-18 11:42:52 +08:00
'sort-imports': [
'error',
{
ignoreCase: false,
ignoreDeclarationSort: true,
ignoreMemberSort: false,
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
allowSeparatedGroups: false,
},
],
2019-07-18 04:11:55 +08:00
},
2019-07-18 03:27:54 +08:00
}