Skip to content

Commit

Permalink
feat: follow antfu's config
Browse files Browse the repository at this point in the history
  • Loading branch information
lvjiaxuan committed Sep 21, 2023
1 parent c8a07a2 commit 52e08a3
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 85 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"@types/eslint": "^8.44.2",
"@types/node": "^20.6.3",
"eslint": "^8.49.0",
"execa": "^8.0.1",
"tsup": "^7.2.0",
"typescript": "^5.2.2",
"unbuild": "^2.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/add.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { execaSync } from 'execa'
import { spawnSync } from 'node:child_process'
import path from 'node:path'
import fs from 'node:fs'

Expand All @@ -11,7 +11,7 @@ try {
const cwd = process.cwd()

// Install
execaSync('ni', [ '@lvjiaxuan/eslint-plugin', 'eslint', '-D', ...argvWithoutFlat ], { stdio: 'inherit', cwd })
spawnSync('ni', [ '@lvjiaxuan/eslint-plugin', 'eslint', '-D', ...argvWithoutFlat ], { stdio: 'inherit', cwd })

if (flat) {
fs.writeFileSync(path.resolve(cwd, 'eslint.config.js'), 'export { default } from \'@lvjiaxuan/eslint-plugin/flat\'', { encoding: 'utf-8' })
Expand Down
23 changes: 16 additions & 7 deletions packages/javascript/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,39 @@ module.exports = {
},
},

// globals: {
// document: 'readonly',
// navigator: 'readonly',
// window: 'readonly',
// },

ignorePatterns: [
'**/*.min.*',
'**/CHANGELOG.md',
'**/dist',
'**/LICENSE*',
'**/output',
'**/out',
'**/coverage',
'**/public',
'**/temp',
'**/packages-lock.json',
'**/package-lock.json',
'**/pnpm-lock.yaml',
'**/yarn.lock',
'**/__snapshots__',
// ignore for in lint-staged
'**/*.css',
'**/*.png',
'**/*.ico',
'**/*.toml',
'**/*.patch',
'**/*.txt',
'**/*.crt',
'**/*.key',
'**/Dockerfile',
// force include
'!**/.github',
'!**/.vitepress',
'!**/.vscode',
// force exclude
'**/.vitepress/cache',
],

// Install plugins as well.
extends: [
'eslint:recommended',
'plugin:promise/recommended',
Expand Down
34 changes: 32 additions & 2 deletions packages/javascript/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,24 @@ module.exports = {
// https://eslint.org/docs/rules/

// My custom rules
indent: [ 'warn', 2 ],
indent: [
'warn', 2, {
SwitchCase: 1,
VariableDeclarator: 1,
outerIIFEBody: 1,
MemberExpression: 1,
FunctionDeclaration: { parameters: 1, body: 1 },
FunctionExpression: { parameters: 1, body: 1 },
CallExpression: { arguments: 1 },
ArrayExpression: 1,
ObjectExpression: 1,
ImportDeclaration: 1,
flatTernaryExpressions: false,
ignoreComments: false,
ignoredNodes: [ 'TemplateLiteral *', 'JSXElement', 'JSXElement > *', 'JSXAttribute', 'JSXIdentifier', 'JSXNamespacedName', 'JSXMemberExpression', 'JSXSpreadAttribute', 'JSXExpressionContainer', 'JSXOpeningElement', 'JSXClosingElement', 'JSXFragment', 'JSXOpeningFragment', 'JSXClosingFragment', 'JSXText', 'JSXEmptyExpression', 'JSXSpreadChild' ],
offsetTernaryExpressions: true,
},
],
semi: [ 'warn', 'never' ], // prettier semi: false
quotes: [ 'warn', 'single' ], // prettier singleQuote: true
'no-empty': [ 'error', { allowEmptyCatch: true } ],
Expand Down Expand Up @@ -161,9 +178,22 @@ module.exports = {
pathPattern: '^(?:dev|peer|optional|bundled)?[Dd]ependencies$',
order: { type: 'asc' },
},
{
pathPattern: '^resolutions$',
order: { type: 'asc' },
},
{
pathPattern: '^pnpm.overrides$',
order: { type: 'asc' },
},
{
pathPattern: '^exports.*$',
order: [ 'types', 'require', 'import' ],
order: [
'types',
'import',
'require',
'default',
],
},
],
},
Expand Down
6 changes: 5 additions & 1 deletion packages/typescript/flat.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import typescript from '@typescript-eslint/eslint-plugin'
import index from './index.cjs'

const config = index.overrides[0]
const tsconfigJsonConfig = index.overrides[1]

/**
* @type {Array.<import('eslint').Linter.FlatConfig>}
Expand All @@ -26,8 +27,11 @@ export default [
parserOptions: config.parserOptions,
},
rules: {
...typescript.configs['eslint-recommended'].rules,
...typescript.configs['eslint-recommended'].overrides[0].rules,
...typescript.configs['recommended-type-checked'].rules,
...typescript.configs['stylistic-type-checked'].rules,
...config.rules,
},
},
tsconfigJsonConfig,
]
167 changes: 164 additions & 3 deletions packages/typescript/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ module.exports = {
},

rules: {
// turn off js rules
...tsRules,

// https://typescript-eslint.io/rules/
'@typescript-eslint/ban-ts-comment': [
'warn', {
Expand Down Expand Up @@ -63,13 +66,171 @@ module.exports = {
ignoreTypeReferences: true,
},
],

// js to ts
...tsRules,
'@typescript-eslint/indent': [
'warn', 2, {
SwitchCase: 1,
VariableDeclarator: 1,
outerIIFEBody: 1,
MemberExpression: 1,
FunctionDeclaration: { parameters: 1, body: 1 },
FunctionExpression: { parameters: 1, body: 1 },
CallExpression: { arguments: 1 },
ArrayExpression: 1,
ObjectExpression: 1,
ImportDeclaration: 1,
flatTernaryExpressions: false,
ignoreComments: false,
ignoredNodes: [
'TemplateLiteral *',
'JSXElement',
'JSXElement > *',
'JSXAttribute',
'JSXIdentifier',
'JSXNamespacedName',
'JSXMemberExpression',
'JSXSpreadAttribute',
'JSXExpressionContainer',
'JSXOpeningElement',
'JSXClosingElement',
'JSXFragment',
'JSXOpeningFragment',
'JSXClosingFragment',
'JSXText',
'JSXEmptyExpression',
'JSXSpreadChild',
'TSTypeParameterInstantiation',
'FunctionExpression > .params[decorators.length > 0]',
'FunctionExpression > .params > :matches(Decorator, :not(:first-child))',
'ClassBody.body > PropertyDefinition[decorators.length > 0] > .key',
],
offsetTernaryExpressions: true,
},
],

// https://typescript-eslint.io/linting/troubleshooting#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
'no-undef': 'off',
},
},
{
files: [ '**/tsconfig.json', '**/tsconfig.*.json' ],
// parser: 'jsonc-eslint-parser',
rules: {
'jsonc/sort-keys': [
'error',
{
pathPattern: '^$',
order: [
'extends',
'compilerOptions',
'references',
'files',
'include',
'exclude',
],
},
{
pathPattern: '^compilerOptions$',
order: [
/* Projects */
'incremental',
'composite',
'tsBuildInfoFile',
'disableSourceOfProjectReferenceRedirect',
'disableSolutionSearching',
'disableReferencedProjectLoad',
/* Language and Environment */
'target',
'lib',
'jsx',
'experimentalDecorators',
'emitDecoratorMetadata',
'jsxFactory',
'jsxFragmentFactory',
'jsxImportSource',
'reactNamespace',
'noLib',
'useDefineForClassFields',
'moduleDetection',
/* Modules */
'module',
'rootDir',
'moduleResolution',
'baseUrl',
'paths',
'rootDirs',
'typeRoots',
'types',
'allowUmdGlobalAccess',
'moduleSuffixes',
'allowImportingTsExtensions',
'resolvePackageJsonExports',
'resolvePackageJsonImports',
'customConditions',
'resolveJsonModule',
'allowArbitraryExtensions',
'noResolve',
/* JavaScript Support */
'allowJs',
'checkJs',
'maxNodeModuleJsDepth',
/* Emit */
'declaration',
'declarationMap',
'emitDeclarationOnly',
'sourceMap',
'inlineSourceMap',
'outFile',
'outDir',
'removeComments',
'noEmit',
'importHelpers',
'importsNotUsedAsValues',
'downlevelIteration',
'sourceRoot',
'mapRoot',
'inlineSources',
'emitBOM',
'newLine',
'stripInternal',
'noEmitHelpers',
'noEmitOnError',
'preserveConstEnums',
'declarationDir',
'preserveValueImports',
/* Interop Constraints */
'isolatedModules',
'verbatimModuleSyntax',
'allowSyntheticDefaultImports',
'esModuleInterop',
'preserveSymlinks',
'forceConsistentCasingInFileNames',
/* Type Checking */
'strict',
'strictBindCallApply',
'strictFunctionTypes',
'strictNullChecks',
'strictPropertyInitialization',
'allowUnreachableCode',
'allowUnusedLabels',
'alwaysStrict',
'exactOptionalPropertyTypes',
'noFallthroughCasesInSwitch',
'noImplicitAny',
'noImplicitOverride',
'noImplicitReturns',
'noImplicitThis',
'noPropertyAccessFromIndexSignature',
'noUncheckedIndexedAccess',
'noUnusedLocals',
'noUnusedParameters',
'useUnknownInCatchVariables',
/* Completeness */
'skipDefaultLibCheck',
'skipLibCheck',
],
},
],
},
},
],
}
2 changes: 1 addition & 1 deletion packages/typescript/tsRules.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"indent":"off","@typescript-eslint/indent":["warn",2],"semi":"off","@typescript-eslint/semi":["warn","never"],"quotes":"off","@typescript-eslint/quotes":["warn","single"],"no-empty-function":"off","@typescript-eslint/no-empty-function":"warn","no-unused-vars":"off","@typescript-eslint/no-unused-vars":"off","comma-dangle":"off","@typescript-eslint/comma-dangle":["warn","always-multiline"],"no-extra-parens":"off","@typescript-eslint/no-extra-parens":"warn","no-use-before-define":"off","@typescript-eslint/no-use-before-define":["error",{"functions":false,"classes":false,"variables":false,"allowNamedExports":true}],"object-curly-spacing":"off","@typescript-eslint/object-curly-spacing":["warn","always"],"comma-spacing":"off","@typescript-eslint/comma-spacing":"warn","keyword-spacing":"off","@typescript-eslint/keyword-spacing":"warn","key-spacing":"off","@typescript-eslint/key-spacing":"warn","block-spacing":"off","@typescript-eslint/block-spacing":"warn","space-infix-ops":"off","@typescript-eslint/space-infix-ops":"warn"}
{"indent":"off","@typescript-eslint/indent":["warn",2,{"SwitchCase":1,"VariableDeclarator":1,"outerIIFEBody":1,"MemberExpression":1,"FunctionDeclaration":{"parameters":1,"body":1},"FunctionExpression":{"parameters":1,"body":1},"CallExpression":{"arguments":1},"ArrayExpression":1,"ObjectExpression":1,"ImportDeclaration":1,"flatTernaryExpressions":false,"ignoreComments":false,"ignoredNodes":["TemplateLiteral *","JSXElement","JSXElement > *","JSXAttribute","JSXIdentifier","JSXNamespacedName","JSXMemberExpression","JSXSpreadAttribute","JSXExpressionContainer","JSXOpeningElement","JSXClosingElement","JSXFragment","JSXOpeningFragment","JSXClosingFragment","JSXText","JSXEmptyExpression","JSXSpreadChild"],"offsetTernaryExpressions":true}],"semi":"off","@typescript-eslint/semi":["warn","never"],"quotes":"off","@typescript-eslint/quotes":["warn","single"],"no-empty-function":"off","@typescript-eslint/no-empty-function":"warn","no-unused-vars":"off","@typescript-eslint/no-unused-vars":"off","comma-dangle":"off","@typescript-eslint/comma-dangle":["warn","always-multiline"],"no-extra-parens":"off","@typescript-eslint/no-extra-parens":"warn","no-use-before-define":"off","@typescript-eslint/no-use-before-define":["error",{"functions":false,"classes":false,"variables":false,"allowNamedExports":true}],"object-curly-spacing":"off","@typescript-eslint/object-curly-spacing":["warn","always"],"comma-spacing":"off","@typescript-eslint/comma-spacing":"warn","keyword-spacing":"off","@typescript-eslint/keyword-spacing":"warn","key-spacing":"off","@typescript-eslint/key-spacing":"warn","block-spacing":"off","@typescript-eslint/block-spacing":"warn","space-infix-ops":"off","@typescript-eslint/space-infix-ops":"warn"}
2 changes: 1 addition & 1 deletion packages/vue/flat.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default [
// TS already checks for that, and Typescript-Eslint recommends to disable it
// https://typescript-eslint.io/linting/troubleshooting#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
'no-undef': 'off',
'@typescript-eslint/no-unused-vars': 'warn',
'@typescript-eslint/no-unused-vars': 'off',
},
},

Expand Down

0 comments on commit 52e08a3

Please sign in to comment.