feat: extract eslint config to separate package (#6495)

This commit is contained in:
三咲智子 2022-03-10 15:39:13 +08:00 committed by GitHub
parent d9b8ec2164
commit 80d903771f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 457 additions and 528 deletions

View File

@ -2,270 +2,5 @@ const { defineConfig } = require('eslint-define-config')
module.exports = defineConfig({
root: true,
env: {
es6: true,
browser: true,
node: true,
},
globals: {
jest: 'readonly',
},
plugins: ['@typescript-eslint', 'prettier', 'unicorn'],
extends: [
'eslint:recommended',
'plugin:import/recommended',
'plugin:eslint-comments/recommended',
'plugin:jsonc/recommended-with-jsonc',
'plugin:markdown/recommended',
'plugin:vue/vue3-recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
],
settings: {
'import/resolver': {
node: { extensions: ['.js', '.mjs', '.ts', '.d.ts', '.tsx'] },
},
},
overrides: [
{
files: ['*.json', '*.json5', '*.jsonc'],
parser: 'jsonc-eslint-parser',
},
{
files: ['*.ts', '*.vue'],
rules: {
'no-undef': 'off',
},
},
{
files: ['**/__tests__/**', '**/gulpfile.ts'],
rules: {
'no-console': 'off',
'vue/one-component-per-file': 'off',
},
},
{
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' },
},
],
},
},
{
files: ['*.d.ts'],
rules: {
'import/no-duplicates': 'off',
},
},
{
files: ['*.js'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
},
},
{
files: ['*.vue'],
parser: 'vue-eslint-parser',
parserOptions: {
parser: '@typescript-eslint/parser',
extraFileExtensions: ['.vue'],
ecmaVersion: 'latest',
ecmaFeatures: {
jsx: true,
},
},
rules: {
'no-undef': 'off',
},
},
{
files: ['**/*.md/*.js', '**/*.md/*.ts'],
rules: {
'no-console': 'off',
'import/no-unresolved': 'off',
'@typescript-eslint/no-unused-vars': 'off',
},
},
],
rules: {
// js/ts
camelcase: ['error', { properties: 'never' }],
'no-console': ['warn', { allow: ['error'] }],
'no-debugger': 'warn',
'no-constant-condition': ['error', { checkLoops: false }],
'no-restricted-syntax': ['error', 'LabeledStatement', 'WithStatement'],
'no-return-await': 'error',
'no-var': 'error',
'no-empty': ['error', { allowEmptyCatch: true }],
'prefer-const': [
'warn',
{ destructuring: 'all', ignoreReadBeforeAssign: true },
],
'prefer-arrow-callback': [
'error',
{ allowNamedFunctions: false, allowUnboundThis: true },
],
'object-shorthand': [
'error',
'always',
{ ignoreConstructors: false, avoidQuotes: true },
],
'prefer-rest-params': 'error',
'prefer-spread': 'error',
'prefer-template': 'error',
'no-redeclare': 'off',
'@typescript-eslint/no-redeclare': 'error',
// best-practice
'array-callback-return': 'error',
'block-scoped-var': 'error',
'no-alert': 'warn',
'no-case-declarations': 'error',
'no-multi-str': 'error',
'no-with': 'error',
'no-void': 'error',
// stylistic-issues
'prefer-exponentiation-operator': 'error',
// ts
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off',
'@typescript-eslint/consistent-type-imports': [
'error',
{ disallowTypeAnnotations: false },
],
// vue
'vue/no-v-html': 'off',
'vue/require-default-prop': 'off',
'vue/require-explicit-emits': 'off',
'vue/multi-word-component-names': 'off',
// prettier
'prettier/prettier': 'error',
// import
'import/first': 'error',
'import/no-duplicates': 'error',
'import/order': [
'error',
{
groups: [
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
'object',
'type',
],
pathGroups: [
{
pattern: 'vue',
group: 'external',
position: 'before',
},
{
pattern: '@vue/**',
group: 'external',
position: 'before',
},
{
pattern: '@element-plus/**',
group: 'internal',
},
],
pathGroupsExcludedImportTypes: ['type'],
},
],
'import/no-unresolved': 'off',
'import/namespace': 'off',
'import/default': 'off',
'import/no-named-as-default': 'off',
'import/no-named-as-default-member': 'off',
'import/named': 'off',
// eslint-plugin-eslint-comments
'eslint-comments/disable-enable-pair': ['error', { allowWholeFile: true }],
// unicorn
'unicorn/custom-error-definition': 'error',
'unicorn/error-message': 'error',
'unicorn/escape-case': 'error',
'unicorn/import-index': 'error',
'unicorn/new-for-builtins': 'error',
'unicorn/no-array-method-this-argument': 'error',
'unicorn/no-array-push-push': 'error',
'unicorn/no-console-spaces': 'error',
'unicorn/no-for-loop': 'error',
'unicorn/no-hex-escape': 'error',
'unicorn/no-instanceof-array': 'error',
'unicorn/no-invalid-remove-event-listener': 'error',
'unicorn/no-new-array': 'error',
'unicorn/no-new-buffer': 'error',
'unicorn/no-unsafe-regex': 'off',
'unicorn/number-literal-case': 'error',
'unicorn/prefer-array-find': 'error',
'unicorn/prefer-array-flat-map': 'error',
'unicorn/prefer-array-index-of': 'error',
'unicorn/prefer-array-some': 'error',
'unicorn/prefer-date-now': 'error',
'unicorn/prefer-dom-node-dataset': 'error',
'unicorn/prefer-includes': 'error',
'unicorn/prefer-keyboard-event-key': 'error',
'unicorn/prefer-math-trunc': 'error',
'unicorn/prefer-modern-dom-apis': 'error',
'unicorn/prefer-negative-index': 'error',
'unicorn/prefer-number-properties': 'error',
'unicorn/prefer-optional-catch-binding': 'error',
'unicorn/prefer-prototype-methods': 'error',
'unicorn/prefer-query-selector': 'error',
'unicorn/prefer-reflect-apply': 'error',
'unicorn/prefer-string-slice': 'error',
'unicorn/prefer-string-starts-ends-with': 'error',
'unicorn/prefer-string-trim-start-end': 'error',
'unicorn/prefer-type-error': 'error',
'unicorn/throw-new-error': 'error',
},
extends: ['@element-plus/eslint-config'],
})

View File

@ -10,7 +10,9 @@
"typescriptreact",
"html",
"vue",
"markdown"
"markdown",
"json",
"jsonc"
],
"eslint.validate": [
"javascript",
@ -19,7 +21,9 @@
"typescriptreact",
"html",
"vue",
"markdown"
"markdown",
"json",
"jsonc"
],
"vite.devCommand": "pnpm run dev -- --",
"i18n-ally.localesPaths": "packages/locale/lang",

3
docs/.eslintignore Normal file
View File

@ -0,0 +1,3 @@
.vitepress/i18n/*
.vitepress/crowdin/*
!.vitepress/crowdin/en-US

View File

@ -27,8 +27,8 @@
"build": "gulp --require sucrase/register/ts -f build/gulpfile.ts",
"build:theme": "pnpm run build -C packages/theme-chalk",
"format": "prettier --write .",
"lint": "eslint . --ext .vue,.js,.ts,.jsx,.tsx,.md --max-warnings 0 && pretty-quick --check --branch dev",
"lint:fix": "eslint --fix . --ext .vue,.js,.ts,.jsx,.tsx,.md && pretty-quick --branch dev",
"lint": "eslint . --ext .vue,.js,.ts,.jsx,.tsx,.md,.json --max-warnings 0 && pretty-quick --check --branch dev",
"lint:fix": "eslint --fix . --ext .vue,.js,.ts,.jsx,.tsx,.md,.json && pretty-quick --branch dev",
"docs:dev": "pnpm run -C docs dev",
"docs:build": "pnpm run -C docs build",
"docs:serve": "pnpm run -C docs serve",
@ -44,7 +44,7 @@
}
},
"lint-staged": {
"*.{vue,js,ts,jsx,tsx,md}": "eslint --fix"
"*.{vue,js,ts,jsx,tsx,md,json}": "eslint --fix"
},
"browserslist": [
"> 1%",
@ -81,6 +81,7 @@
"@babel/preset-typescript": "^7.16.7",
"@commitlint/cli": "^16.2.1",
"@commitlint/config-conventional": "^16.2.1",
"@element-plus/eslint-config": "workspace:*",
"@pnpm/find-workspace-packages": "^3.1.42",
"@pnpm/logger": "^4.0.0",
"@pnpm/types": "^7.10.0",
@ -94,8 +95,6 @@
"@types/node": "^17.0.18",
"@types/rollup-plugin-css-only": "^3.1.0",
"@types/sass": "^1.43.1",
"@typescript-eslint/eslint-plugin": "^5.13.0",
"@typescript-eslint/parser": "^5.13.0",
"@vitejs/plugin-vue": "^2.2.4",
"@vitejs/plugin-vue-jsx": "^1.3.8",
"@vitest/ui": "^0.5.9",
@ -111,22 +110,13 @@
"cz-conventional-changelog": "^3.3.0",
"esbuild": "^0.14.25",
"eslint": "^8.10.0",
"eslint-config-prettier": "^8.5.0",
"eslint-define-config": "^1.2.5",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jsonc": "^2.2.1",
"eslint-plugin-markdown": "^2.2.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-unicorn": "^41.0.0",
"eslint-plugin-vue": "^8.5.0",
"expect-type": "^0.13.0",
"fast-glob": "^3.2.11",
"fs-extra": "^10.0.1",
"gulp": "^4.0.2",
"husky": "^7.0.4",
"jest": "^26.6.3",
"jsonc-eslint-parser": "^2.1.0",
"lint-staged": "^12.3.5",
"prettier": "^2.5.1",
"pretty-quick": "^3.1.3",
@ -147,8 +137,7 @@
"vue": "^3.2.31",
"vue-jest": "^5.0.0-alpha.10",
"vue-router": "^4.0.13",
"vue-tsc": "^0.32.1",
"yaml-eslint-parser": "^0.5.0"
"vue-tsc": "^0.32.1"
},
"pnpm": {
"overrides": {

View File

@ -2,13 +2,13 @@
"name": "@element-plus/components",
"version": "0.0.5",
"description": "all components are settled here",
"main": "index.ts",
"module": "index.ts",
"unpkg": "index.js",
"peerDependencies": {
"vue": "^3.2.0"
},
"main": "index.ts",
"module": "index.ts",
"types": "index.d.ts",
"unpkg": "index.js",
"jsdelivr": "index.js",
"sideEffects": false,
"gitHead": "c69724230befa8fede0e6b9c37fb0b7e39fd7cdd"

View File

@ -1,12 +1,12 @@
{
"name": "@element-plus/directives",
"description": "Element Plus directives",
"version": "0.0.5",
"description": "Element Plus directives",
"license": "MIT",
"main": "index.ts",
"module": "index.ts",
"unpkg": "index.js",
"jsdelivr": "index.js",
"license": "MIT",
"peerDependencies": {
"vue": "^3.2.0"
},

View File

@ -12,6 +12,10 @@
"vue"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/element-plus/element-plus.git"
},
"exports": {
".": {
"require": "./lib/index.js",
@ -37,10 +41,6 @@
"es/components/*/style/*",
"lib/components/*/style/*"
],
"repository": {
"type": "git",
"url": "git+https://github.com/element-plus/element-plus.git"
},
"bugs": {
"url": "https://github.com/element-plus/element-plus/issues"
},

View File

@ -0,0 +1,270 @@
const { defineConfig } = require('eslint-define-config')
module.exports = defineConfig({
env: {
es6: true,
browser: true,
node: true,
},
globals: {
jest: 'readonly',
},
plugins: ['@typescript-eslint', 'prettier', 'unicorn'],
extends: [
'eslint:recommended',
'plugin:import/recommended',
'plugin:eslint-comments/recommended',
'plugin:jsonc/recommended-with-jsonc',
'plugin:markdown/recommended',
'plugin:vue/vue3-recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
],
settings: {
'import/resolver': {
node: { extensions: ['.js', '.mjs', '.ts', '.d.ts', '.tsx'] },
},
},
overrides: [
{
files: ['*.json', '*.json5', '*.jsonc'],
parser: 'jsonc-eslint-parser',
},
{
files: ['*.ts', '*.vue'],
rules: {
'no-undef': 'off',
},
},
{
files: ['**/__tests__/**', '**/gulpfile.ts'],
rules: {
'no-console': 'off',
'vue/one-component-per-file': 'off',
},
},
{
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' },
},
],
},
},
{
files: ['*.d.ts'],
rules: {
'import/no-duplicates': 'off',
},
},
{
files: ['*.js'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
},
},
{
files: ['*.vue'],
parser: 'vue-eslint-parser',
parserOptions: {
parser: '@typescript-eslint/parser',
extraFileExtensions: ['.vue'],
ecmaVersion: 'latest',
ecmaFeatures: {
jsx: true,
},
},
rules: {
'no-undef': 'off',
},
},
{
files: ['**/*.md/*.js', '**/*.md/*.ts'],
rules: {
'no-console': 'off',
'import/no-unresolved': 'off',
'@typescript-eslint/no-unused-vars': 'off',
},
},
],
rules: {
// js/ts
camelcase: ['error', { properties: 'never' }],
'no-console': ['warn', { allow: ['error'] }],
'no-debugger': 'warn',
'no-constant-condition': ['error', { checkLoops: false }],
'no-restricted-syntax': ['error', 'LabeledStatement', 'WithStatement'],
'no-return-await': 'error',
'no-var': 'error',
'no-empty': ['error', { allowEmptyCatch: true }],
'prefer-const': [
'warn',
{ destructuring: 'all', ignoreReadBeforeAssign: true },
],
'prefer-arrow-callback': [
'error',
{ allowNamedFunctions: false, allowUnboundThis: true },
],
'object-shorthand': [
'error',
'always',
{ ignoreConstructors: false, avoidQuotes: true },
],
'prefer-rest-params': 'error',
'prefer-spread': 'error',
'prefer-template': 'error',
'no-redeclare': 'off',
'@typescript-eslint/no-redeclare': 'error',
// best-practice
'array-callback-return': 'error',
'block-scoped-var': 'error',
'no-alert': 'warn',
'no-case-declarations': 'error',
'no-multi-str': 'error',
'no-with': 'error',
'no-void': 'error',
// stylistic-issues
'prefer-exponentiation-operator': 'error',
// ts
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off',
'@typescript-eslint/consistent-type-imports': [
'error',
{ disallowTypeAnnotations: false },
],
// vue
'vue/no-v-html': 'off',
'vue/require-default-prop': 'off',
'vue/require-explicit-emits': 'off',
'vue/multi-word-component-names': 'off',
// prettier
'prettier/prettier': 'error',
// import
'import/first': 'error',
'import/no-duplicates': 'error',
'import/order': [
'error',
{
groups: [
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
'object',
'type',
],
pathGroups: [
{
pattern: 'vue',
group: 'external',
position: 'before',
},
{
pattern: '@vue/**',
group: 'external',
position: 'before',
},
{
pattern: '@element-plus/**',
group: 'internal',
},
],
pathGroupsExcludedImportTypes: ['type'],
},
],
'import/no-unresolved': 'off',
'import/namespace': 'off',
'import/default': 'off',
'import/no-named-as-default': 'off',
'import/no-named-as-default-member': 'off',
'import/named': 'off',
// eslint-plugin-eslint-comments
'eslint-comments/disable-enable-pair': ['error', { allowWholeFile: true }],
// unicorn
'unicorn/custom-error-definition': 'error',
'unicorn/error-message': 'error',
'unicorn/escape-case': 'error',
'unicorn/import-index': 'error',
'unicorn/new-for-builtins': 'error',
'unicorn/no-array-method-this-argument': 'error',
'unicorn/no-array-push-push': 'error',
'unicorn/no-console-spaces': 'error',
'unicorn/no-for-loop': 'error',
'unicorn/no-hex-escape': 'error',
'unicorn/no-instanceof-array': 'error',
'unicorn/no-invalid-remove-event-listener': 'error',
'unicorn/no-new-array': 'error',
'unicorn/no-new-buffer': 'error',
'unicorn/no-unsafe-regex': 'off',
'unicorn/number-literal-case': 'error',
'unicorn/prefer-array-find': 'error',
'unicorn/prefer-array-flat-map': 'error',
'unicorn/prefer-array-index-of': 'error',
'unicorn/prefer-array-some': 'error',
'unicorn/prefer-date-now': 'error',
'unicorn/prefer-dom-node-dataset': 'error',
'unicorn/prefer-includes': 'error',
'unicorn/prefer-keyboard-event-key': 'error',
'unicorn/prefer-math-trunc': 'error',
'unicorn/prefer-modern-dom-apis': 'error',
'unicorn/prefer-negative-index': 'error',
'unicorn/prefer-number-properties': 'error',
'unicorn/prefer-optional-catch-binding': 'error',
'unicorn/prefer-prototype-methods': 'error',
'unicorn/prefer-query-selector': 'error',
'unicorn/prefer-reflect-apply': 'error',
'unicorn/prefer-string-slice': 'error',
'unicorn/prefer-string-starts-ends-with': 'error',
'unicorn/prefer-string-trim-start-end': 'error',
'unicorn/prefer-type-error': 'error',
'unicorn/throw-new-error': 'error',
},
})

View File

@ -0,0 +1,30 @@
{
"name": "@element-plus/eslint-config",
"version": "0.0.1",
"description": "ESLint Config",
"license": "MIT",
"files": [
"index.js"
],
"main": "index.js",
"scripts": {},
"private": true,
"peerDependencies": {
"eslint": "^8.0.0"
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "^5.13.0",
"@typescript-eslint/parser": "^5.13.0",
"eslint-config-prettier": "^8.5.0",
"eslint-define-config": "^1.2.5",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jsonc": "^2.2.1",
"eslint-plugin-markdown": "^2.2.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-unicorn": "^41.0.0",
"eslint-plugin-vue": "^8.5.0",
"jsonc-eslint-parser": "^2.1.0",
"yaml-eslint-parser": "^0.5.0"
}
}

View File

@ -1,13 +1,13 @@
{
"name": "@element-plus/hooks",
"description": "Element Plus composables",
"version": "0.0.5",
"description": "Element Plus composables",
"license": "MIT",
"main": "index.ts",
"module": "index.ts",
"unpkg": "index.js",
"jsdelivr": "index.js",
"types": "index.d.ts",
"license": "MIT",
"peerDependencies": {
"vue": "^3.2.0"
},

View File

@ -1,12 +1,12 @@
{
"name": "@element-plus/locale",
"description": "Element Plus locale",
"version": "0.0.5",
"description": "Element Plus locale",
"license": "MIT",
"main": "index.ts",
"module": "index.ts",
"unpkg": "index.js",
"jsdelivr": "index.js",
"types": "index.d.ts",
"license": "MIT",
"gitHead": "c69724230befa8fede0e6b9c37fb0b7e39fd7cdd"
}

View File

@ -2,6 +2,6 @@
"name": "@element-plus/test-utils",
"private": true,
"version": "0.0.5",
"main": "dist/index.js",
"license": "MIT"
"license": "MIT",
"main": "dist/index.js"
}

View File

@ -2,6 +2,18 @@
"name": "@element-plus/theme-chalk",
"version": "0.1.0",
"description": "Element component chalk theme.",
"keywords": [
"vue-components",
"element-plus",
"theme-chalk",
"theme-light"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/element-plus/element-plus.git"
},
"author": "yi.shyang@ele.me",
"main": "index.css",
"unpkg": "index.css",
"jsdelivr": "index.css",
@ -10,18 +22,6 @@
"clean": "rimraf dist",
"build": "gulp --require sucrase/register/ts"
},
"repository": {
"type": "git",
"url": "git+https://github.com/element-plus/element-plus.git"
},
"keywords": [
"vue-components",
"element-plus",
"theme-chalk",
"theme-light"
],
"author": "yi.shyang@ele.me",
"license": "MIT",
"bugs": {
"url": "https://github.com/element-plus/element-plus#issues"
},

View File

@ -2,13 +2,13 @@
"name": "@element-plus/tokens",
"version": "0.0.5",
"license": "MIT",
"main": "index.ts",
"module": "index.ts",
"unpkg": "index.js",
"peerDependencies": {
"vue": "^3.2.0"
},
"main": "index.ts",
"module": "index.ts",
"types": "index.d.js",
"unpkg": "index.js",
"jsdelivr": "index.js",
"gitHead": "c69724230befa8fede0e6b9c37fb0b7e39fd7cdd"
}

File diff suppressed because it is too large Load Diff