@lntvow/eslint-config 8.5.0 → 9.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/.czrc +3 -0
  2. package/.editorconfig +14 -0
  3. package/.env.development +1 -0
  4. package/.env.production +1 -0
  5. package/.env.uat +1 -0
  6. package/.github/workflows/publish-npm.yml +44 -0
  7. package/.husky/commit-msg +4 -0
  8. package/.husky/pre-commit +4 -0
  9. package/.lintstagedrc +4 -0
  10. package/.prettierrc +10 -0
  11. package/.vscode/settings.json +14 -0
  12. package/README.md +19 -27
  13. package/api/basic.js +22 -0
  14. package/api/vue.js +34 -0
  15. package/commitlint.config.cjs +4 -0
  16. package/eslint.config.js +21 -0
  17. package/package.json +46 -11
  18. package/packages/eslint-config-ts/index.js +85 -0
  19. package/packages/eslint-config-ts/package.json +18 -0
  20. package/packages/eslint-plugin/index.js +5 -0
  21. package/packages/eslint-plugin/package.json +16 -0
  22. package/packages/eslint-plugin/rules/get.js +18 -0
  23. package/packages/eslint-plugin/test/get.test.js +39 -0
  24. package/src/configs/gitignore.ts +34 -0
  25. package/src/configs/ignores.ts +10 -0
  26. package/src/configs/imports.ts +17 -0
  27. package/src/configs/index.ts +8 -0
  28. package/src/configs/javascript.ts +161 -0
  29. package/src/configs/prettier.ts +18 -0
  30. package/src/configs/stylistic.ts +59 -0
  31. package/src/configs/typescript.ts +63 -0
  32. package/src/configs/vue.ts +316 -0
  33. package/src/factory.ts +167 -0
  34. package/src/globs.ts +86 -0
  35. package/src/index.ts +7 -0
  36. package/src/typegen.d.ts +15123 -0
  37. package/src/types.ts +127 -0
  38. package/src/typings/index.d.ts +3 -0
  39. package/src/utils/index.ts +30 -0
  40. package/test/js.vue +28 -0
  41. package/test/jsx.vue +27 -0
  42. package/test/test.js +11 -0
  43. package/test/test.ts +18 -0
  44. package/test/ts.vue +26 -0
  45. package/test/tsx.vue +23 -0
  46. package/tsconfig.json +20 -0
  47. package/tsup.config.ts +10 -0
  48. package/index.js +0 -3
package/.czrc ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "path": "cz-conventional-changelog"
3
+ }
package/.editorconfig ADDED
@@ -0,0 +1,14 @@
1
+ # https://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ charset = utf-8
6
+ indent_style = space
7
+ indent_size = 2
8
+ end_of_line = lf
9
+ insert_final_newline = true
10
+ trim_trailing_whitespace = true
11
+
12
+ [*.md]
13
+ insert_final_newline = false
14
+ trim_trailing_whitespace = false
@@ -0,0 +1 @@
1
+ VITE_BASE = '/xxxxx/'
@@ -0,0 +1 @@
1
+ VITE_BASE = '/xxxxx/'
package/.env.uat ADDED
@@ -0,0 +1 @@
1
+ VITE_BASE = '/xxxxx/'
@@ -0,0 +1,44 @@
1
+ name: publish-npm
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ push:
6
+ paths:
7
+ # - 'package.json'
8
+
9
+ jobs:
10
+ publish-npm:
11
+ runs-on: ubuntu-latest
12
+ timeout-minutes: 10
13
+ steps:
14
+ - name: Checkout
15
+ uses: actions/checkout@v3
16
+
17
+ - name: Set Node
18
+ uses: actions/setup-node@v3
19
+ with:
20
+ node-version: 20
21
+ registry-url: https://registry.npmjs.org
22
+
23
+ - name: Set pnpm
24
+ uses: pnpm/action-setup@v2
25
+ with:
26
+ version: 9
27
+
28
+ - name: Get pnpm store directory
29
+ shell: bash
30
+ run: |
31
+ echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
32
+
33
+ - uses: actions/cache@v3
34
+ name: Setup pnpm cache
35
+ with:
36
+ path: ${{ env.STORE_PATH }}
37
+ key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
38
+ restore-keys: |
39
+ ${{ runner.os }}-pnpm-store-
40
+
41
+ - run: pnpm install
42
+ - run: pnpm publish --access public
43
+ env:
44
+ NODE_AUTH_TOKEN: ${{secrets.NPM_PUBLISH}}
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env sh
2
+ . "$(dirname -- "$0")/_/husky.sh"
3
+
4
+ # npx commitlint --edit $1
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env sh
2
+ . "$(dirname -- "$0")/_/husky.sh"
3
+
4
+ # npx lint-staged
package/.lintstagedrc ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "*.{js,jsx,ts,tsx,vue}": ["eslint --fix"],
3
+ "*.{json,css,scss,md}": ["prettier --write"]
4
+ }
package/.prettierrc ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "printWidth": 120,
3
+ "semi": false,
4
+ "singleQuote": true,
5
+ "arrowParens": "avoid",
6
+ "trailingComma": "es5",
7
+ "htmlWhitespaceSensitivity": "ignore",
8
+ "quoteProps": "consistent",
9
+ "jsxSingleQuote": true
10
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "cSpell.words": [
3
+ "astro",
4
+ "backreference",
5
+ "bumpp",
6
+ "JETBRAINS",
7
+ "nonconstructor",
8
+ "nonoctal",
9
+ "plusplus",
10
+ "tsup",
11
+ "typedefs",
12
+ "unignore"
13
+ ]
14
+ }
package/README.md CHANGED
@@ -1,37 +1,29 @@
1
- ## 安装
1
+ # @lntvow/eslint-config
2
2
 
3
- 安装 @lntvow/eslint-config
3
+ ## Usage
4
4
 
5
- ```
5
+ install @lntvow/eslint-config
6
+
7
+ ```bash
6
8
  pnpm install -D @lntvow/eslint-config
7
9
  ```
8
10
 
9
- 然后在你的.`eslintrc.*`文件的 "extends" 字段里添加 "@lntvow" 如下图所示
11
+ create `eslint.config.mjs` in your project root
10
12
 
11
- ```json
12
- {
13
- "extends": ["@lntvow"]
14
- }
15
- ```
13
+ ```js
14
+ // eslint.config.mjs
15
+ import lntvow from '@lntvow/eslint-config'
16
16
 
17
- ## 温馨提示
17
+ export default lntvow()
18
+ ```
18
19
 
19
- 1. 如果项目是 `npm` 或者 `yarn` 安装的跳过本提示
20
- 2. 由于 `pnpm` 软链和 `eslint` 以及 `prettier` 功能冲突 所以部分包必须平铺在 `node_modules` 根目录下
21
- 3. 项目根目录下新建文件 `.npmrc` 并写入 `shamefully-hoist=true` 该指令表示平铺依赖到 `node_modules` 根目录
20
+ ## Plugins
22
21
 
23
- ```
24
- shamefully-hoist=true
25
- ```
22
+ Since flat config requires us to explicitly provide the plugin names (instead of the mandatory convention from npm package name), we renamed some plugins to make the overall scope more consistent and easier to write.
26
23
 
27
- 本项目使用的依赖如下:
28
-
29
- - [eslint]
30
- - [prettier]
31
- - [eslint-plugin-prettier]
32
- - [eslint-plugin-import]
33
- - [eslint-import-resolver-alias]
34
- - [eslint-plugin-unicorn]
35
- - [@typescript-eslint/eslint-plugin]
36
- - [@typescript-eslint/parser]
37
- - [eslint-plugin-vue]
24
+ | New Prefix | Original Prefix | Source Plugin |
25
+ | -------------- | ---------------------- | ------------------------------------------------------------------------------------------ |
26
+ | `typescript/*` | `@typescript-eslint/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) |
27
+ | `vue/*` | `@vue/*` | [eslint-plugin-vue](https://github.com/vuejs/eslint-plugin-vue) |
28
+ | `import/*` | `import-x/*` | [eslint-plugin-import-x](https://github.com/un-es/eslint-plugin-import-x) |
29
+ | `style/*` | `@stylistic/*` | [@stylistic/eslint-plugin](https://github.com/eslint-stylistic/eslint-stylistic) |
package/api/basic.js ADDED
@@ -0,0 +1,22 @@
1
+ import * as cheerio from 'cheerio'
2
+ import axios from 'axios'
3
+ import { javascript } from '../dist/index.js'
4
+
5
+ // Const basicKeys = Object.keys(basicRules);
6
+ const rulesMap = {}
7
+
8
+ axios.get('https://eslint.org/docs/latest/rules/').then(async res => {
9
+ const $ = cheerio.load(res.data),
10
+ filteredElements = $('.rule').filter((i, e) => !($(e).is('.rule--deprecated') || $(e).is('.rule--removed')))
11
+
12
+ filteredElements.each((i, el) => {
13
+ const ruleName = $(el).find('.rule__name').text()
14
+ rulesMap[ruleName] = 2
15
+ })
16
+
17
+ const keyList = Object.keys(rulesMap)
18
+ const rulesList = Object.keys((await javascript())[0].rules)
19
+
20
+ const diff = keyList.filter(key => !rulesList.includes(key))
21
+ console.log('diff: ', diff)
22
+ })
package/api/vue.js ADDED
@@ -0,0 +1,34 @@
1
+ /* eslint-disable unicorn/prefer-top-level-await */
2
+ const axios = require('axios')
3
+ const cheerio = require('cheerio')
4
+ const { rules } = require('../packages/eslint-config-vue')
5
+
6
+ const keys = Object.keys(rules)
7
+ const eslintKeys = []
8
+
9
+ axios.get('https://eslint.vuejs.org/rules/').then(res => {
10
+ const $ = cheerio.load(res.data)
11
+
12
+ const filteredElements = $('.group').filter((i, e) => {
13
+ return ['Extension Rules', 'Uncategorized'].includes($(e).find('.item[tabindex="0"] .text').text())
14
+ })
15
+
16
+ filteredElements.each((i, el) => {
17
+ const list = $(el).find('.items .is-link')
18
+ list.each((i, e) => {
19
+ const ruleName = $(e).find('.item .text').text()
20
+ eslintKeys.push(ruleName)
21
+ })
22
+ })
23
+
24
+ const diff = eslintKeys.filter(key => !keys.includes(key))
25
+ console.log('eslintKeys: ', eslintKeys)
26
+ console.log('diff: ', diff)
27
+ })
28
+
29
+ /**
30
+ * @deprecated 使用 isEmail
31
+ */
32
+ export function validatorEmail(value) {
33
+ return /^([\w-])+@([\w-])+(\.[\w-])+/.test(value)
34
+ }
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ extends: ['@commitlint/config-conventional'],
3
+ rules: {},
4
+ }
@@ -0,0 +1,21 @@
1
+ import pluginStylistic from '@stylistic/eslint-plugin'
2
+ import { lntvow, GLOB_SRC, renameRules } from './dist/index.js'
3
+
4
+ const config = await lntvow({
5
+ vue: true,
6
+ typescript: true,
7
+ gitignore: {
8
+ },
9
+ })
10
+
11
+ const files = [GLOB_SRC]
12
+
13
+ // 1
14
+ export default [
15
+ ...config,
16
+ {
17
+ // rules: {
18
+ // 'style/quotes': 'error',
19
+ // },
20
+ },
21
+ ]
package/package.json CHANGED
@@ -1,19 +1,54 @@
1
1
  {
2
2
  "name": "@lntvow/eslint-config",
3
- "version": "8.5.0",
4
- "description": "eslint配置文件",
5
- "main": "index.js",
6
- "keywords": [],
3
+ "version": "9.1.2",
7
4
  "author": "lntvow",
5
+ "description": "eslint-config",
6
+ "type": "module",
8
7
  "license": "MIT",
9
- "files": [
10
- "index.js",
11
- "README.md"
12
- ],
8
+ "engines": {
9
+ "node": ">=18.12.0",
10
+ "pnpm": ">=9.0.0"
11
+ },
12
+ "main": "./dist/index.js",
13
+ "module": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "devDependencies": {
16
+ "@types/eslint": "^8.56.10",
17
+ "@types/eslint-config-prettier": "^6.11.3",
18
+ "@types/node": "^20.12.12",
19
+ "axios": "^1.7.2",
20
+ "bumpp": "^9.4.1",
21
+ "cheerio": "1.0.0-rc.12",
22
+ "rimraf": "^5.0.7",
23
+ "tsup": "^8.0.2",
24
+ "typescript": "^5.4.5",
25
+ "vue": "^3.4.27"
26
+ },
13
27
  "dependencies": {
14
- "@lntvow/eslint-config-vue": "8.5.0"
28
+ "@eslint/js": "^9.3.0",
29
+ "@lntvow/utils": "^3.0.3",
30
+ "@stylistic/eslint-plugin": "^2.1.0",
31
+ "@typescript-eslint/eslint-plugin": "^7.10.0",
32
+ "@typescript-eslint/parser": "^7.10.0",
33
+ "eslint": "^9.3.0",
34
+ "eslint-config-prettier": "^9.1.0",
35
+ "eslint-flat-config-utils": "^0.2.5",
36
+ "eslint-plugin-import-x": "^0.5.0",
37
+ "eslint-plugin-prettier": "^5.1.3",
38
+ "eslint-plugin-vue": "^9.26.0",
39
+ "find-up": "^7.0.0",
40
+ "globals": "^15.3.0",
41
+ "local-pkg": "^0.5.0",
42
+ "parse-gitignore": "^2.0.0",
43
+ "tslib": "^2.6.2",
44
+ "typescript": "^5.4.5",
45
+ "vue-eslint-parser": "^9.4.2"
15
46
  },
16
- "peerDependencies": {
17
- "eslint": "^8.43.0"
47
+ "scripts": {
48
+ "dev": "pnpm build --watch",
49
+ "build": "tsup",
50
+ "commit": "git add . && git-cz",
51
+ "rimraf": "rimraf ./node_modules/",
52
+ "release": "git add . && bumpp package.json --all --commit --no-tag --push"
18
53
  }
19
54
  }
@@ -0,0 +1,85 @@
1
+ module.exports = {
2
+ extends: [
3
+ '@lntvow/eslint-config-basic',
4
+ 'plugin:import/typescript',
5
+ 'plugin:@typescript-eslint/strict',
6
+ 'plugin:@typescript-eslint/stylistic',
7
+ ],
8
+ settings: {
9
+ 'import/resolver': { typescript: true },
10
+ },
11
+ overrides: [
12
+ {
13
+ files: ['*.js', '*.cjs'],
14
+ // 禁用js文件的类型检查
15
+ extends: ['plugin:@typescript-eslint/disable-type-checked'],
16
+ rules: {
17
+ '@typescript-eslint/no-var-requires': 0, // 允许使用require
18
+ '@typescript-eslint/consistent-type-assertions': 0, // 禁用js文件的类型检查
19
+ },
20
+ },
21
+ {
22
+ files: ['*.ts', '*.tsx', '*.d.ts'],
23
+ // 禁用js文件的类型检查
24
+ rules: {
25
+ 'spaced-comment': 0, // 警用注释检查
26
+ },
27
+ },
28
+ {
29
+ files: ['*.ts', '*.tsx', '*.vue'],
30
+ rules: {
31
+ /**
32
+ * 重写import规则
33
+ */
34
+ 'import/namespace': 0, // 导入校验
35
+ 'import/no-cycle': 0, // 循环导入
36
+ 'import/no-unused-modules': 0, // 导入未使用的模块
37
+ 'import/no-named-as-default': 0, // 校验导出名称
38
+ 'import/no-unresolved': 0, // 导入目录校验
39
+
40
+ /**
41
+ * 重写ts规则
42
+ */
43
+ '@typescript-eslint/no-non-null-assertion': 0, // 允许使用!断言
44
+ '@typescript-eslint/ban-types': 0, // 允许使用object
45
+ '@typescript-eslint/no-explicit-any': 0, // 允许使用any
46
+ '@typescript-eslint/ban-ts-comment': 0, // 允许使用ts注释
47
+
48
+ '@typescript-eslint/no-unused-vars': 1, // 未使用的变量 警告
49
+
50
+ /**
51
+ * 重写js规则
52
+ */
53
+ 'no-undef': 0, // ts自带 允许使用未定义的变量
54
+ 'no-use-before-define': 0,
55
+ '@typescript-eslint/no-use-before-define': [
56
+ 2,
57
+ {
58
+ functions: false,
59
+ classes: true,
60
+ variables: false,
61
+ allowNamedExports: false,
62
+ enums: true,
63
+ typedefs: true,
64
+ ignoreTypeReferences: true,
65
+ },
66
+ ], // 变量定义前禁止使用
67
+ 'lines-around-comment': 'off',
68
+ '@typescript-eslint/lines-around-comment': [
69
+ 2,
70
+ {
71
+ allowBlockStart: true,
72
+ allowObjectStart: true,
73
+ allowArrayStart: true,
74
+ allowClassStart: true,
75
+ allowEnumStart: true,
76
+ allowInterfaceStart: true,
77
+ allowModuleStart: true,
78
+ allowTypeStart: true,
79
+ },
80
+ ], // 注释空行,
81
+ },
82
+ },
83
+ ],
84
+ rules: {},
85
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@lntvow/eslint-config-ts",
3
+ "version": "8.5.0",
4
+ "description": "eslint/ts配置文件",
5
+ "main": "index.js",
6
+ "keywords": [],
7
+ "author": "lntvow",
8
+ "license": "MIT",
9
+ "files": [
10
+ "index.js"
11
+ ],
12
+ "dependencies": {
13
+ "@lntvow/eslint-config-basic": "workspace:*",
14
+ "@typescript-eslint/eslint-plugin": "^6.2.0",
15
+ "@typescript-eslint/parser": "^6.2.0",
16
+ "eslint-import-resolver-typescript": "^3.5.5"
17
+ }
18
+ }
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ rules: {
3
+ get: require('./rules/get'),
4
+ },
5
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "@lntvow/eslint-plugin",
3
+ "version": "8.5.0",
4
+ "description": "eslint/plugin文件",
5
+ "main": "index.js",
6
+ "keywords": [],
7
+ "author": "lntvow",
8
+ "license": "MIT",
9
+ "files": [
10
+ "index.js"
11
+ ],
12
+ "dependencies": {},
13
+ "peerDependencies": {
14
+ "eslint": ">=8.43.0"
15
+ }
16
+ }
@@ -0,0 +1,18 @@
1
+ module.exports = {
2
+ create(content) {
3
+ const options = content.options[1]
4
+ return {
5
+ ExpressionStatement(node) {
6
+ const callee = node.expression.callee
7
+ console.log('callee: ', callee)
8
+ const name = callee.property.name
9
+ if (options[name] === 2) {
10
+ content.report({
11
+ node,
12
+ message: `不能使用console.${name}`,
13
+ })
14
+ }
15
+ },
16
+ }
17
+ },
18
+ }
@@ -0,0 +1,39 @@
1
+ const rule = require('../rules/get')
2
+ const RuleTester = require('eslint').RuleTester
3
+
4
+ const ruleTester = new RuleTester()
5
+
6
+ ruleTester.run('get', rule, {
7
+ valid: [
8
+ {
9
+ name: 'success',
10
+ code: 'var a = 10',
11
+ },
12
+ ],
13
+ invalid: [
14
+ {
15
+ name: 'hash log',
16
+ code: "console.log('context: ', context.options)",
17
+ options: [
18
+ 2,
19
+ {
20
+ log: 2,
21
+ warn: 2,
22
+ },
23
+ ],
24
+ errors: [{ message: '不能使用console.log' }],
25
+ },
26
+ {
27
+ name: 'hash warn',
28
+ code: "console.warn('context: ', context.options)",
29
+ options: [
30
+ 2,
31
+ {
32
+ log: 2,
33
+ warn: 2,
34
+ },
35
+ ],
36
+ errors: [{ message: '不能使用console.warn' }],
37
+ },
38
+ ],
39
+ })
@@ -0,0 +1,34 @@
1
+ import fs from 'fs'
2
+ import { findUpSync } from 'find-up'
3
+ import { castArray } from '@lntvow/utils'
4
+ import parse from 'parse-gitignore'
5
+ import type { FlatGitignoreOptions, TypedFlatConfigItem } from '../types'
6
+
7
+ export async function gitignore(options: FlatGitignoreOptions): Promise<TypedFlatConfigItem[]> {
8
+ const { name = '.gitignore', root = false, files: _files = root ? name : findUpSync(name) || [] } = options
9
+ const files = castArray(_files)
10
+
11
+ const ignores = []
12
+ for (const file of files) {
13
+ try {
14
+ const content = fs.readFileSync(file, 'utf8')
15
+
16
+ const globs = parse(content).globs()
17
+ for (const glob of globs) {
18
+ if (glob.type === 'ignore') {
19
+ ignores.push(...glob.patterns)
20
+ } else if (glob.type === 'unignore') {
21
+ ignores.push(...glob.patterns.map((pattern: string) => `!${pattern}`))
22
+ }
23
+ }
24
+ } catch (error) {
25
+ throw new Error(`Failed to read file: ${file}`)
26
+ }
27
+ }
28
+
29
+ return [
30
+ {
31
+ ignores,
32
+ },
33
+ ]
34
+ }
@@ -0,0 +1,10 @@
1
+ import { GLOB_EXCLUDE } from 'src/globs'
2
+ import type { TypedFlatConfigItem } from '../types'
3
+
4
+ export async function ignores(): Promise<TypedFlatConfigItem[]> {
5
+ return [
6
+ {
7
+ ignores: [...GLOB_EXCLUDE],
8
+ },
9
+ ]
10
+ }
@@ -0,0 +1,17 @@
1
+ import pluginImport from 'eslint-plugin-import-x'
2
+ import type { TypedFlatConfigItem } from '../types'
3
+
4
+ export async function imports(): Promise<TypedFlatConfigItem[]> {
5
+ return [
6
+ {
7
+ name: 'lntvow/imports/rules',
8
+ plugins: {
9
+ import: pluginImport,
10
+ },
11
+ rules: {
12
+ 'import/order': 'error',
13
+ 'import/newline-after-import': 'error',
14
+ },
15
+ },
16
+ ]
17
+ }
@@ -0,0 +1,8 @@
1
+ export * from './gitignore'
2
+ export * from './ignores'
3
+ export * from './imports'
4
+ export * from './javascript'
5
+ export * from './prettier'
6
+ export * from './stylistic'
7
+ export * from './typescript'
8
+ export * from './vue'