@ocavue/eslint-config 0.5.0-beta.3 → 1.1.0

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.
package/README.md CHANGED
@@ -5,6 +5,7 @@ A set of ESLint shareable configs for TypeScript projects.
5
5
  - Out of the box support for TypeScript, React, and Markdown
6
6
  - Sort your imports
7
7
  - Sort your fields in `package.json`
8
+ - Prefer top-level function declarations over function expressions
8
9
 
9
10
  ## Install
10
11
 
@@ -75,3 +76,8 @@ If you are using VS Code, you and install [ESLint extension](https://marketplace
75
76
  }
76
77
  }
77
78
  ```
79
+
80
+ ## Inspired by
81
+
82
+ - https://github.com/antfu/eslint-config
83
+ - https://github.com/sxzz/eslint-config
@@ -0,0 +1,3 @@
1
+ declare const _default: import("eslint-define-config").FlatESLintConfig[];
2
+ export default _default;
3
+ //# sourceMappingURL=eslint.config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eslint.config.d.ts","sourceRoot":"","sources":["../eslint.config.js"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export function antfu(): import("eslint-define-config").FlatESLintConfigItem[];
2
+ //# sourceMappingURL=antfu.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"antfu.d.ts","sourceRoot":"","sources":["../../src/antfu.js"],"names":[],"mappings":"AAEA,+EAcC"}
@@ -1,3 +1,10 @@
1
+ /**
2
+ * @typedef {Object} BasicOptions
3
+ * @property {import('./typescript.js').TypescriptOptions} [typescript]
4
+ */
5
+ /**
6
+ * @param {BasicOptions} [options]
7
+ */
1
8
  export function basic(options?: BasicOptions | undefined): import("eslint-define-config").FlatESLintConfigItem[];
2
9
  export type BasicOptions = {
3
10
  typescript?: import("./typescript.js").TypescriptOptions | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"basic.d.ts","sourceRoot":"","sources":["../../src/basic.js"],"names":[],"mappings":"AAkBO,iHAgBN"}
1
+ {"version":3,"file":"basic.d.ts","sourceRoot":"","sources":["../../src/basic.js"],"names":[],"mappings":"AAWA;;;GAGG;AAEH;;GAEG;AACH,iHAiBC"}
@@ -1 +1 @@
1
- {"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../../src/imports.js"],"names":[],"mappings":"AAKO,iFAyCN"}
1
+ {"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../../src/imports.js"],"names":[],"mappings":"AAKA,iFA0CC"}
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/markdown.js"],"names":[],"mappings":"AAOO,kFA0DN"}
1
+ {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/markdown.js"],"names":[],"mappings":"AAOA,kFA0DC"}
@@ -1 +1 @@
1
- {"version":3,"file":"no-only-tests.d.ts","sourceRoot":"","sources":["../../src/no-only-tests.js"],"names":[],"mappings":"AAKO,qFAcN"}
1
+ {"version":3,"file":"no-only-tests.d.ts","sourceRoot":"","sources":["../../src/no-only-tests.js"],"names":[],"mappings":"AAKA,qFAcC"}
@@ -1,2 +1,5 @@
1
+ /**
2
+ * Sort package.json keys
3
+ */
1
4
  export function packageJson(): import("eslint-define-config").FlatESLintConfigItem[];
2
5
  //# sourceMappingURL=package-json.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"package-json.d.ts","sourceRoot":"","sources":["../../src/package-json.js"],"names":[],"mappings":"AAUO,qFA0EN"}
1
+ {"version":3,"file":"package-json.d.ts","sourceRoot":"","sources":["../../src/package-json.js"],"names":[],"mappings":"AAOA;;GAEG;AACH,qFA0EC"}
@@ -1,2 +1,8 @@
1
+ /**
2
+ * Turns off all rules that are unnecessary or might conflict with Prettier.
3
+ *
4
+ * Notice that this config does not run `prettier` as an ESLint rule, so you
5
+ * have to run `pretter` separately for formatting.
6
+ */
1
7
  export function prettier(): import("eslint-define-config").FlatESLintConfigItem[];
2
8
  //# sourceMappingURL=prettier.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prettier.d.ts","sourceRoot":"","sources":["../../src/prettier.js"],"names":[],"mappings":"AAQO,kFAWN"}
1
+ {"version":3,"file":"prettier.d.ts","sourceRoot":"","sources":["../../src/prettier.js"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,kFAWC"}
@@ -1 +1 @@
1
- {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/react.js"],"names":[],"mappings":"AASO,+EAwCN"}
1
+ {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/react.js"],"names":[],"mappings":"AASA,+EAwCC"}
@@ -20,6 +20,6 @@ export const GLOB_ALL_SRC: readonly ["**/*.?([mt])[jt]s?(x)", "**/*.{c,le,sc}ss"
20
20
  export const GLOB_NODE_MODULES: "**/node_modules";
21
21
  export const GLOB_DIST: "**/dist";
22
22
  export const GLOB_LOCKFILE: readonly ["**/package-lock.json", "**/yarn.lock", "**/pnpm-lock.yaml"];
23
- export const GLOB_EXCLUDE: readonly ["**/node_modules", "**/dist", "**/package-lock.json", "**/yarn.lock", "**/pnpm-lock.yaml", "**/output", "**/coverage", "**/temp", "**/fixtures", "**/.vitepress/cache", "**/.next", "**/.nuxt", "**/.vercel", "**/.changeset", "**/.idea", "**/.output", "**/.vite-inspect", "**/dist-types", "**/CHANGELOG*.md", "**/*.min.*", "**/LICENSE*", "**/__snapshots__"];
23
+ export const GLOB_EXCLUDE: readonly ["**/node_modules", "**/dist", "**/package-lock.json", "**/yarn.lock", "**/pnpm-lock.yaml", "**/output", "**/coverage", "**/temp", "**/fixtures", "**/.vitepress/cache", "**/.next", "**/.nuxt", "**/.vercel", "**/.changeset", "**/.idea", "**/.output", "**/.vite-inspect", "**/.yalc", "**/dist-types", "**/CHANGELOG*.md", "**/*.min.*", "**/LICENSE*", "**/__snapshots__"];
24
24
  export const EXTENSIONS: string[];
25
25
  //# sourceMappingURL=shared.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/shared.js"],"names":[],"mappings":"AAEA,8CAA8C;AAC9C,+CAA+C;AAE/C,uCAAuC;AACvC,yCAAyC;AAEzC,uCAAuC;AACvC,yCAAyC;AAEzC,4CAA4C;AAC5C,kCAAkC;AAClC,oCAAoC;AACpC,oCAAoC;AAEpC,oCAAoC;AACpC,sCAAsC;AACtC,sCAAsC;AAEtC,kDAAkD;AAElD,sCAAsC;AACtC,kCAAkC;AAClC,uCAAuC;AACvC,uCAAuC;AAEvC,oKASE;AAEF,kDAAyE;AACzE,kCAAyD;AACzD,mGAIE;AACF,wYAuBE;AAEF,kCAGsC"}
1
+ {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/shared.js"],"names":[],"mappings":"AAEA,8CAA8C;AAC9C,+CAA+C;AAE/C,uCAAuC;AACvC,yCAAyC;AAEzC,uCAAuC;AACvC,yCAAyC;AAEzC,4CAA4C;AAC5C,kCAAkC;AAClC,oCAAoC;AACpC,oCAAoC;AAEpC,oCAAoC;AACpC,sCAAsC;AACtC,sCAAsC;AAEtC,kDAAkD;AAElD,sCAAsC;AACtC,kCAAkC;AAClC,uCAAuC;AACvC,uCAAuC;AAEvC,oKASE;AAEF,kDAAyE;AACzE,kCAAyD;AACzD,mGAIE;AACF,oZAwBE;AAEF,kCAGsC"}
@@ -1,3 +1,11 @@
1
+ /**
2
+ * @typedef {Object} TypescriptOptions
3
+ * @property {string | false} [project] - Path to tsconfig.json, defaults
4
+ * to './tsconfig.json'. You can pass `false` to disable the tsconfig.json check.
5
+ */
6
+ /**
7
+ * @param {TypescriptOptions} [options]
8
+ */
1
9
  export function typescript(options?: TypescriptOptions | undefined): import("eslint-define-config").FlatESLintConfigItem[];
2
10
  export type TypescriptOptions = {
3
11
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../../src/typescript.js"],"names":[],"mappings":"AAkBO,2HAwDN;;;;;;;;qBAvEoB,2BAA2B;qBAD3B,kCAAkC"}
1
+ {"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../../src/typescript.js"],"names":[],"mappings":"AASA;;;;GAIG;AAEH;;GAEG;AACH,2HAsEC;;;;;;;;qBArFoB,2BAA2B;qBAD3B,kCAAkC"}
@@ -1 +1 @@
1
- {"version":3,"file":"unicorn.d.ts","sourceRoot":"","sources":["../../src/unicorn.js"],"names":[],"mappings":"AAKO,iFA+DN"}
1
+ {"version":3,"file":"unicorn.d.ts","sourceRoot":"","sources":["../../src/unicorn.js"],"names":[],"mappings":"AAKA,iFA+DC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ocavue/eslint-config",
3
3
  "type": "module",
4
- "version": "0.5.0-beta.3",
4
+ "version": "1.1.0",
5
5
  "packageManager": "pnpm@8.5.1",
6
6
  "description": "",
7
7
  "author": "ocavue <ocavue@gmail.com>",
@@ -23,6 +23,13 @@
23
23
  "src",
24
24
  "dist"
25
25
  ],
26
+ "scripts": {
27
+ "build": "tsc",
28
+ "lint": "eslint .",
29
+ "check": "prettier --check .",
30
+ "fix": "eslint --fix . && prettier --write .",
31
+ "prepublishOnly": "nr build"
32
+ },
26
33
  "dependencies": {
27
34
  "@types/eslint": "^8.40.0",
28
35
  "@typescript-eslint/eslint-plugin": "^5.59.7",
@@ -30,6 +37,7 @@
30
37
  "eslint-config-prettier": "^8.8.0",
31
38
  "eslint-define-config": "^1.20.0",
32
39
  "eslint-import-resolver-typescript": "^3.5.5",
40
+ "eslint-plugin-antfu": "^0.39.3",
33
41
  "eslint-plugin-import": "^2.27.5",
34
42
  "eslint-plugin-jsonc": "^2.8.0",
35
43
  "eslint-plugin-markdown": "^3.0.0",
@@ -51,11 +59,5 @@
51
59
  "extends": [
52
60
  "github>ocavue/config-renovate"
53
61
  ]
54
- },
55
- "scripts": {
56
- "build": "tsc",
57
- "lint": "eslint .",
58
- "check": "prettier --check .",
59
- "fix": "eslint --fix . && prettier --write ."
60
62
  }
61
- }
63
+ }
package/src/antfu.js ADDED
@@ -0,0 +1,17 @@
1
+ import antfuPlugin from 'eslint-plugin-antfu'
2
+
3
+ export function antfu() {
4
+ /** @type {import('eslint-define-config').FlatESLintConfigItem[]} */
5
+ const config = [
6
+ {
7
+ plugins: {
8
+ antfu: antfuPlugin,
9
+ },
10
+ rules: {
11
+ 'antfu/top-level-function': 'error',
12
+ },
13
+ },
14
+ ]
15
+
16
+ return config
17
+ }
package/src/basic.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // @ts-check
2
2
 
3
+ import { antfu } from './antfu.js'
3
4
  import { imports } from './imports.js'
4
5
  import { noOnlyTests } from './no-only-tests.js'
5
6
  import { packageJson } from './package-json.js'
@@ -16,17 +17,18 @@ import { unicorn } from './unicorn.js'
16
17
  /**
17
18
  * @param {BasicOptions} [options]
18
19
  */
19
- export const basic = (options) => {
20
+ export function basic(options) {
20
21
  /** @type {import('eslint-define-config').FlatESLintConfigItem[]} */
21
22
  const config = [
22
23
  {
23
- // @ts-ignore
24
+ // @ts-expect-error: 'readonly' and cannot be assigned to the mutable type 'string[]'
24
25
  ignores: GLOB_EXCLUDE,
25
26
  },
26
27
  ...typescript(options?.typescript),
27
28
  ...imports(),
28
29
  ...packageJson(),
29
30
  ...unicorn(),
31
+ ...antfu(),
30
32
  ...noOnlyTests(),
31
33
  ...prettier(),
32
34
  ]
package/src/imports.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // @ts-expect-error no type
4
4
  import importPlugin from 'eslint-plugin-import'
5
5
 
6
- export const imports = () => {
6
+ export function imports() {
7
7
  /** @type {import('eslint-define-config').FlatESLintConfigItem[]} */
8
8
  const config = [
9
9
  {
@@ -23,7 +23,8 @@ export const imports = () => {
23
23
  'import/no-extraneous-dependencies': 'warn',
24
24
  'import/first': 'warn',
25
25
  'import/no-mutable-exports': 'warn',
26
- 'import/no-duplicates': 'warn',
26
+ 'import/no-useless-path-segments': 'warn',
27
+ 'import/newline-after-import': 'warn',
27
28
  'import/order': [
28
29
  'warn',
29
30
  {
@@ -33,9 +34,9 @@ export const imports = () => {
33
34
  'builtin',
34
35
  'external',
35
36
  'internal',
36
- ['parent', 'sibling'],
37
+ 'parent',
38
+ 'sibling',
37
39
  'index',
38
- 'type',
39
40
  ],
40
41
  },
41
42
  ],
package/src/markdown.js CHANGED
@@ -5,7 +5,7 @@ import markdownPlugin from 'eslint-plugin-markdown'
5
5
 
6
6
  import { GLOB_MARKDOWN, GLOB_SRC, GLOB_VUE } from './shared.js'
7
7
 
8
- export const markdown = () => {
8
+ export function markdown() {
9
9
  /** @type {import('eslint-define-config').FlatESLintConfigItem[]} */
10
10
  const config = [
11
11
  {
@@ -3,7 +3,7 @@
3
3
  // @ts-expect-error: eslint-plugin-unicorn is not typed
4
4
  import plugin from 'eslint-plugin-no-only-tests'
5
5
 
6
- export const noOnlyTests = () => {
6
+ export function noOnlyTests() {
7
7
  /** @type {import('eslint-define-config').FlatESLintConfigItem[]} */
8
8
  const config = [
9
9
  {
@@ -8,7 +8,7 @@ import { GLOB_PACKAGE_JSON } from './shared.js'
8
8
  /**
9
9
  * Sort package.json keys
10
10
  */
11
- export const packageJson = () => {
11
+ export function packageJson() {
12
12
  /** @type {import('eslint-define-config').FlatESLintConfigItem[]} */
13
13
  const config = [
14
14
  {
package/src/prettier.js CHANGED
@@ -6,7 +6,7 @@ import prettierConfig from 'eslint-config-prettier'
6
6
  * Notice that this config does not run `prettier` as an ESLint rule, so you
7
7
  * have to run `pretter` separately for formatting.
8
8
  */
9
- export const prettier = () => {
9
+ export function prettier() {
10
10
  /** @type {import('eslint-define-config').FlatESLintConfigItem[]} */
11
11
  const config = [
12
12
  {
package/src/react.js CHANGED
@@ -7,7 +7,7 @@ import reactHooksPlugin from 'eslint-plugin-react-hooks'
7
7
 
8
8
  import { GLOB_TSX } from './shared.js'
9
9
 
10
- export const react = () => {
10
+ export function react() {
11
11
  /** @type {import('eslint-define-config').FlatESLintConfigItem[]} */
12
12
  const config = [
13
13
  {
package/src/shared.js CHANGED
@@ -60,6 +60,7 @@ export const GLOB_EXCLUDE = /** @type {const} */ ([
60
60
  '**/.idea',
61
61
  '**/.output',
62
62
  '**/.vite-inspect',
63
+ '**/.yalc',
63
64
  '**/dist-types',
64
65
 
65
66
  '**/CHANGELOG*.md',
package/src/typescript.js CHANGED
@@ -3,7 +3,7 @@
3
3
  import tsPlugin from '@typescript-eslint/eslint-plugin'
4
4
  import tsParser from '@typescript-eslint/parser'
5
5
 
6
- import { GLOB_TS, GLOB_TSX } from './shared.js'
6
+ import { GLOB_JS, GLOB_JSX, GLOB_TS, GLOB_TSX } from './shared.js'
7
7
 
8
8
  export { tsParser, tsPlugin }
9
9
 
@@ -16,13 +16,13 @@ export { tsParser, tsPlugin }
16
16
  /**
17
17
  * @param {TypescriptOptions} [options]
18
18
  */
19
- export const typescript = (options) => {
19
+ export function typescript(options) {
20
20
  const project = options?.project ?? './tsconfig.json'
21
21
 
22
22
  /** @type {import('eslint-define-config').FlatESLintConfigItem[]} */
23
23
  const config = [
24
24
  {
25
- files: [GLOB_TS, GLOB_TSX],
25
+ files: [GLOB_TS, GLOB_TSX, GLOB_JS, GLOB_JSX],
26
26
  languageOptions: {
27
27
  // @ts-expect-error: the types for `parser` seems to be wrong
28
28
  parser: tsParser,
@@ -48,9 +48,17 @@ export const typescript = (options) => {
48
48
  ? tsPlugin.configs['recommended-requiring-type-checking'].rules
49
49
  : null),
50
50
 
51
+ '@typescript-eslint/no-unsafe-call': 'warn',
52
+ '@typescript-eslint/restrict-plus-operands': 'warn',
53
+ '@typescript-eslint/no-unsafe-return': 'warn',
54
+ '@typescript-eslint/no-unsafe-argument': 'warn',
55
+ '@typescript-eslint/no-unsafe-member-access': 'warn',
56
+ '@typescript-eslint/no-unsafe-assignment': 'warn',
57
+ '@typescript-eslint/no-floating-promises': 'warn',
51
58
  '@typescript-eslint/no-explicit-any': 'warn',
52
59
  '@typescript-eslint/explicit-module-boundary-types': 'off',
53
60
  '@typescript-eslint/no-non-null-assertion': 'off',
61
+ '@typescript-eslint/restrict-template-expressions': 'off',
54
62
  '@typescript-eslint/no-unused-vars': [
55
63
  'error',
56
64
  {
@@ -61,6 +69,12 @@ export const typescript = (options) => {
61
69
  ],
62
70
  '@typescript-eslint/no-extra-semi': 'off',
63
71
  '@typescript-eslint/prefer-function-type': 'warn',
72
+
73
+ // TODO: We should set the rules below to error in the future
74
+ '@typescript-eslint/no-misused-promises': 'warn',
75
+ '@typescript-eslint/await-thenable': 'warn',
76
+ '@typescript-eslint/require-await': 'warn',
77
+ '@typescript-eslint/unbound-method': 'warn',
64
78
  },
65
79
  },
66
80
  {
package/src/unicorn.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // @ts-expect-error: eslint-plugin-unicorn is not typed
4
4
  import plugin from 'eslint-plugin-unicorn'
5
5
 
6
- export const unicorn = () => {
6
+ export function unicorn() {
7
7
  /** @type {import('eslint-define-config').FlatESLintConfigItem[]} */
8
8
  const config = [
9
9
  {
@@ -42,7 +42,7 @@ export const unicorn = () => {
42
42
  // Improve regexes
43
43
  'unicorn/better-regex': 'error',
44
44
  // Enforce combining multiple `Array#push()` into one call.
45
- 'unicorn/no-array-push-push': 'error',
45
+ 'unicorn/no-array-push-push': 'warn',
46
46
  // Do not use a `for` loop that can be replaced with a `for-of` loop.
47
47
  'unicorn/no-for-loop': 'error',
48
48
  // Prefer `.addEventListener()` and `.removeEventListener()` over `on`-functions.
@@ -60,7 +60,7 @@ export const unicorn = () => {
60
60
  // Prefer negative index over `.length - index` when possible
61
61
  'unicorn/prefer-negative-index': 'error',
62
62
  // Prefer `Number` static properties over global ones.
63
- 'unicorn/prefer-number-properties': 'error',
63
+ 'unicorn/prefer-number-properties': 'warn',
64
64
  },
65
65
  },
66
66
  ]