@ocavue/eslint-config 0.4.7 → 1.0.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
@@ -1,6 +1,10 @@
1
1
  # @ocavue/eslint-config
2
2
 
3
- A set of ESLint rules for TypeScript projects.
3
+ A set of ESLint shareable configs for TypeScript projects.
4
+
5
+ - Out of the box support for TypeScript, React, and Markdown
6
+ - Sort your imports
7
+ - Sort your fields in `package.json`
4
8
 
5
9
  ## Install
6
10
 
@@ -10,11 +14,64 @@ $ npm install -D eslint prettier @ocavue/eslint-config
10
14
 
11
15
  ## Usage
12
16
 
13
- In your ESLint configuration file
17
+ ### Config ESLint
18
+
19
+ You will need to use the new ["flat" ESLint configuration](https://eslint.org/docs/latest/use/configure/configuration-files-new) (i.e. `eslint.config.js`).
20
+
21
+ In your `eslint.config.js` file, add the following to extend the basic config:
22
+
23
+ ```JS
24
+ // eslint.config.js
25
+ import { basic } from '@ocavue/eslint-config'
26
+
27
+ export default [...basic()]
28
+ ```
29
+
30
+ If you want to use the React config, you can do the following:
31
+
32
+ ```JS
33
+ // eslint.config.js
34
+ import { basic, react } from '@ocavue/eslint-config'
35
+
36
+ export default [...basic(), ...react()]
37
+ ```
38
+
39
+ If you want to use the check the code blocks in markdown files, you can do the following:
14
40
 
15
41
  ```JS
16
- // .eslintrc.cjs
17
- module.exports = {
18
- extends: ['@ocavue/eslint-config'],
42
+ // eslint.config.js
43
+ import { basic, markdown } from '@ocavue/eslint-config'
44
+
45
+ export default [...basic(), ...markdown()]
46
+ ```
47
+
48
+ ### Add script for package.json
49
+
50
+ ```json
51
+ {
52
+ "scripts": {
53
+ "lint": "eslint .",
54
+ "check": "prettier --check .",
55
+ "fix": "eslint --fix . && prettier --write ."
56
+ }
57
+ }
58
+ ```
59
+
60
+ ### Add `.prettierignore`
61
+
62
+ Add a [`.prettierignore`](https://prettier.io/docs/en/ignore.html#ignoring-files-prettierignore) file in the root of your project. You can copy the `.prettierignore` file from this project.
63
+
64
+ ### VS Code integration
65
+
66
+ If you are using VS Code, you and install [ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) and [Prettier extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode), then add the following to your VS Code settings:
67
+
68
+ ```json
69
+ // .vscode/settings.json
70
+ {
71
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
72
+ "editor.formatOnSave": true,
73
+ "editor.codeActionsOnSave": {
74
+ "source.fixAll.eslint": true
75
+ }
19
76
  }
20
77
  ```
@@ -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,6 @@
1
+ export * from "./src/typescript.js";
2
+ export * from "./src/prettier.js";
3
+ export * from "./src/basic.js";
4
+ export * from "./src/markdown.js";
5
+ export * from "./src/react.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.js"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ export function basic(options?: BasicOptions | undefined): import("eslint-define-config").FlatESLintConfigItem[];
2
+ export type BasicOptions = {
3
+ typescript?: import("./typescript.js").TypescriptOptions | undefined;
4
+ };
5
+ //# sourceMappingURL=basic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basic.d.ts","sourceRoot":"","sources":["../../src/basic.js"],"names":[],"mappings":"AAkBO,iHAgBN"}
@@ -0,0 +1,2 @@
1
+ export function imports(): import("eslint-define-config").FlatESLintConfigItem[];
2
+ //# sourceMappingURL=imports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../../src/imports.js"],"names":[],"mappings":"AAKO,iFA0CN"}
@@ -0,0 +1,2 @@
1
+ export function markdown(): import("eslint-define-config").FlatESLintConfigItem[];
2
+ //# sourceMappingURL=markdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/markdown.js"],"names":[],"mappings":"AAOO,kFA0DN"}
@@ -0,0 +1,2 @@
1
+ export function noOnlyTests(): import("eslint-define-config").FlatESLintConfigItem[];
2
+ //# sourceMappingURL=no-only-tests.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-only-tests.d.ts","sourceRoot":"","sources":["../../src/no-only-tests.js"],"names":[],"mappings":"AAKO,qFAcN"}
@@ -0,0 +1,2 @@
1
+ export function packageJson(): import("eslint-define-config").FlatESLintConfigItem[];
2
+ //# sourceMappingURL=package-json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-json.d.ts","sourceRoot":"","sources":["../../src/package-json.js"],"names":[],"mappings":"AAUO,qFA0EN"}
@@ -0,0 +1,2 @@
1
+ export function prettier(): import("eslint-define-config").FlatESLintConfigItem[];
2
+ //# sourceMappingURL=prettier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prettier.d.ts","sourceRoot":"","sources":["../../src/prettier.js"],"names":[],"mappings":"AAQO,kFAWN"}
@@ -0,0 +1,2 @@
1
+ export function react(): import("eslint-define-config").FlatESLintConfigItem[];
2
+ //# sourceMappingURL=react.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/react.js"],"names":[],"mappings":"AASO,+EAwCN"}
@@ -0,0 +1,25 @@
1
+ export const GLOB_SRC_EXT: "?([mt])[jt]s?(x)";
2
+ export const GLOB_SRC: "**/*.?([mt])[jt]s?(x)";
3
+ export const GLOB_JS: "**/*.?([mt])js";
4
+ export const GLOB_JSX: "**/*.?([mt])jsx";
5
+ export const GLOB_TS: "**/*.?([mt])ts";
6
+ export const GLOB_TSX: "**/*.?([mt])tsx";
7
+ export const GLOB_STYLE: "**/*.{c,le,sc}ss";
8
+ export const GLOB_CSS: "**/*.css";
9
+ export const GLOB_LESS: "**/*.less";
10
+ export const GLOB_SCSS: "**/*.scss";
11
+ export const GLOB_JSON: "**/*.json";
12
+ export const GLOB_JSON5: "**/*.json5";
13
+ export const GLOB_JSONC: "**/*.jsonc";
14
+ export const GLOB_PACKAGE_JSON: "**/package.json";
15
+ export const GLOB_MARKDOWN: "**/*.md";
16
+ export const GLOB_VUE: "**/*.vue";
17
+ export const GLOB_YAML: "**/*.y?(a)ml";
18
+ export const GLOB_HTML: "**/*.htm?(l)";
19
+ export const GLOB_ALL_SRC: readonly ["**/*.?([mt])[jt]s?(x)", "**/*.{c,le,sc}ss", "**/*.json", "**/*.json5", "**/*.md", "**/*.vue", "**/*.y?(a)ml", "**/*.htm?(l)"];
20
+ export const GLOB_NODE_MODULES: "**/node_modules";
21
+ export const GLOB_DIST: "**/dist";
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", "**/.yalc", "**/dist-types", "**/CHANGELOG*.md", "**/*.min.*", "**/LICENSE*", "**/__snapshots__"];
24
+ export const EXTENSIONS: string[];
25
+ //# sourceMappingURL=shared.d.ts.map
@@ -0,0 +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,oZAwBE;AAEF,kCAGsC"}
@@ -0,0 +1,12 @@
1
+ export function typescript(options?: TypescriptOptions | undefined): import("eslint-define-config").FlatESLintConfigItem[];
2
+ export type TypescriptOptions = {
3
+ /**
4
+ * - Path to tsconfig.json, defaults
5
+ * to './tsconfig.json'. You can pass `false` to disable the tsconfig.json check.
6
+ */
7
+ project?: string | false | undefined;
8
+ };
9
+ import tsParser from '@typescript-eslint/parser';
10
+ import tsPlugin from '@typescript-eslint/eslint-plugin';
11
+ export { tsParser, tsPlugin };
12
+ //# sourceMappingURL=typescript.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../../src/typescript.js"],"names":[],"mappings":"AAkBO,2HAsEN;;;;;;;;qBArFoB,2BAA2B;qBAD3B,kCAAkC"}
@@ -0,0 +1,2 @@
1
+ export function unicorn(): import("eslint-define-config").FlatESLintConfigItem[];
2
+ //# sourceMappingURL=unicorn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unicorn.d.ts","sourceRoot":"","sources":["../../src/unicorn.js"],"names":[],"mappings":"AAKO,iFA+DN"}
package/index.js CHANGED
@@ -1,10 +1,5 @@
1
- // @ts-check
2
-
3
- const { defineConfig } = require('eslint-define-config')
4
- const basic = require('@ocavue/eslint-config-basic')
5
-
6
- module.exports = defineConfig({
7
- extends: ['@ocavue/eslint-config-basic', '@ocavue/eslint-config-prettier'],
8
-
9
- overrides: basic.overrides,
10
- })
1
+ export * from './src/typescript.js'
2
+ export * from './src/prettier.js'
3
+ export * from './src/basic.js'
4
+ export * from './src/markdown.js'
5
+ export * from './src/react.js'
package/package.json CHANGED
@@ -1,29 +1,62 @@
1
1
  {
2
2
  "name": "@ocavue/eslint-config",
3
- "version": "0.4.7",
3
+ "type": "module",
4
+ "version": "1.0.0",
5
+ "packageManager": "pnpm@8.5.1",
6
+ "description": "",
7
+ "author": "ocavue <ocavue@gmail.com>",
8
+ "license": "MIT",
4
9
  "funding": "https://github.com/sponsors/ocavue",
5
10
  "homepage": "https://github.com/ocavue/eslint-config#readme",
6
11
  "repository": {
7
12
  "type": "git",
8
- "url": "https://github.com/ocavue/eslint-config.git",
9
- "directory": "packages/eslint-config"
13
+ "url": "https://github.com/ocavue/eslint-config.git"
10
14
  },
11
15
  "bugs": "https://github.com/ocavue/eslint-config/issues",
12
- "main": "index.js",
13
- "dependencies": {
14
- "@ocavue/eslint-config-basic": "^0.6.5",
15
- "@ocavue/eslint-config-prettier": "^0.4.3",
16
- "eslint-define-config": "^1.13.0"
16
+ "keywords": [],
17
+ "sideEffects": false,
18
+ "main": "./index.js",
19
+ "module": "./index.js",
20
+ "types": "./dist/index.d.ts",
21
+ "files": [
22
+ "index.js",
23
+ "src",
24
+ "dist"
25
+ ],
26
+ "scripts": {
27
+ "build": "tsc",
28
+ "lint": "eslint .",
29
+ "check": "prettier --check .",
30
+ "fix": "eslint --fix . && prettier --write .",
31
+ "prepublishOnly": "nr build"
17
32
  },
18
- "peerDependencies": {
19
- "eslint": ">=8.0.0"
33
+ "dependencies": {
34
+ "@types/eslint": "^8.40.0",
35
+ "@typescript-eslint/eslint-plugin": "^5.59.7",
36
+ "@typescript-eslint/parser": "^5.59.7",
37
+ "eslint-config-prettier": "^8.8.0",
38
+ "eslint-define-config": "^1.20.0",
39
+ "eslint-import-resolver-typescript": "^3.5.5",
40
+ "eslint-plugin-import": "^2.27.5",
41
+ "eslint-plugin-jsonc": "^2.8.0",
42
+ "eslint-plugin-markdown": "^3.0.0",
43
+ "eslint-plugin-no-only-tests": "^3.1.0",
44
+ "eslint-plugin-react": "^7.32.2",
45
+ "eslint-plugin-react-hooks": "^4.6.0",
46
+ "eslint-plugin-unicorn": "^47.0.0",
47
+ "jsonc-eslint-parser": "^2.3.0"
20
48
  },
21
49
  "devDependencies": {
22
- "eslint": "^8.31.0",
23
- "prettier": "^2.8.2",
24
- "typescript": "~4.9.4"
50
+ "@antfu/ni": "^0.21.3",
51
+ "@types/eslint-plugin-markdown": "^2.0.0",
52
+ "@types/node": "^18.16.15",
53
+ "eslint": "^8.41.0",
54
+ "prettier": "^2.8.8",
55
+ "typescript": "^5.0.4"
25
56
  },
26
- "publishConfig": {
27
- "access": "public"
57
+ "renovate": {
58
+ "extends": [
59
+ "github>ocavue/config-renovate"
60
+ ]
28
61
  }
29
- }
62
+ }
package/src/basic.js ADDED
@@ -0,0 +1,35 @@
1
+ // @ts-check
2
+
3
+ import { imports } from './imports.js'
4
+ import { noOnlyTests } from './no-only-tests.js'
5
+ import { packageJson } from './package-json.js'
6
+ import { prettier } from './prettier.js'
7
+ import { GLOB_EXCLUDE } from './shared.js'
8
+ import { typescript } from './typescript.js'
9
+ import { unicorn } from './unicorn.js'
10
+
11
+ /**
12
+ * @typedef {Object} BasicOptions
13
+ * @property {import('./typescript.js').TypescriptOptions} [typescript]
14
+ */
15
+
16
+ /**
17
+ * @param {BasicOptions} [options]
18
+ */
19
+ export const basic = (options) => {
20
+ /** @type {import('eslint-define-config').FlatESLintConfigItem[]} */
21
+ const config = [
22
+ {
23
+ // @ts-expect-error: 'readonly' and cannot be assigned to the mutable type 'string[]'
24
+ ignores: GLOB_EXCLUDE,
25
+ },
26
+ ...typescript(options?.typescript),
27
+ ...imports(),
28
+ ...packageJson(),
29
+ ...unicorn(),
30
+ ...noOnlyTests(),
31
+ ...prettier(),
32
+ ]
33
+
34
+ return config
35
+ }
package/src/imports.js ADDED
@@ -0,0 +1,48 @@
1
+ // @ts-check
2
+
3
+ // @ts-expect-error no type
4
+ import importPlugin from 'eslint-plugin-import'
5
+
6
+ export const imports = () => {
7
+ /** @type {import('eslint-define-config').FlatESLintConfigItem[]} */
8
+ const config = [
9
+ {
10
+ plugins: {
11
+ import: importPlugin,
12
+ },
13
+ settings: {
14
+ 'import/resolver': {
15
+ // You will also need to install and configure the TypeScript resolver
16
+ // See also https://github.com/import-js/eslint-import-resolver-typescript#configuration
17
+ typescript: true,
18
+ node: true,
19
+ },
20
+ },
21
+ rules: {
22
+ // External modules must be declared in the package.json
23
+ 'import/no-extraneous-dependencies': 'warn',
24
+ 'import/first': 'warn',
25
+ 'import/no-mutable-exports': 'warn',
26
+ 'import/no-useless-path-segments': 'warn',
27
+ 'import/newline-after-import': 'warn',
28
+ 'import/order': [
29
+ 'warn',
30
+ {
31
+ 'newlines-between': 'always',
32
+ alphabetize: { order: 'asc' },
33
+ groups: [
34
+ 'builtin',
35
+ 'external',
36
+ 'internal',
37
+ 'parent',
38
+ 'sibling',
39
+ 'index',
40
+ ],
41
+ },
42
+ ],
43
+ },
44
+ },
45
+ ]
46
+
47
+ return config
48
+ }
@@ -0,0 +1,66 @@
1
+ // @ts-check
2
+
3
+ import tsPlugin from '@typescript-eslint/eslint-plugin'
4
+ import markdownPlugin from 'eslint-plugin-markdown'
5
+
6
+ import { GLOB_MARKDOWN, GLOB_SRC, GLOB_VUE } from './shared.js'
7
+
8
+ export const markdown = () => {
9
+ /** @type {import('eslint-define-config').FlatESLintConfigItem[]} */
10
+ const config = [
11
+ {
12
+ files: [GLOB_MARKDOWN],
13
+ plugins: {
14
+ markdown: markdownPlugin,
15
+ },
16
+ processor: 'markdown/markdown',
17
+ },
18
+ {
19
+ files: [`${GLOB_MARKDOWN}/${GLOB_SRC}`, `${GLOB_MARKDOWN}/${GLOB_VUE}`],
20
+ languageOptions: {
21
+ parserOptions: {
22
+ ecmaFeatures: {
23
+ impliedStrict: true,
24
+ },
25
+ },
26
+ },
27
+ plugins: {
28
+ // @ts-expect-error: wrong typing
29
+ '@typescript-eslint': tsPlugin,
30
+ },
31
+ rules: {
32
+ '@typescript-eslint/no-redeclare': 'off',
33
+ '@typescript-eslint/no-unused-vars': 'off',
34
+ '@typescript-eslint/no-use-before-define': 'off',
35
+ '@typescript-eslint/no-var-requires': 'off',
36
+ 'no-alert': 'off',
37
+ 'no-console': 'off',
38
+ 'no-restricted-imports': 'off',
39
+
40
+ // Below are taken from https://github.com/eslint/eslint-plugin-markdown/blob/v3.0.0/lib/index.js#L31-L52
41
+
42
+ // The Markdown parser automatically trims trailing
43
+ // newlines from code blocks.
44
+ 'eol-last': 'off',
45
+
46
+ // In code snippets and examples, these rules are often
47
+ // counterproductive to clarity and brevity.
48
+ 'no-undef': 'off',
49
+ 'no-unused-expressions': 'off',
50
+ 'no-unused-vars': 'off',
51
+ 'padded-blocks': 'off',
52
+
53
+ // Adding a "use strict" directive at the top of every
54
+ // code block is tedious and distracting. The config
55
+ // opts into strict mode parsing without the directive.
56
+ strict: 'off',
57
+
58
+ // The processor will not receive a Unicode Byte Order
59
+ // Mark from the Markdown parser.
60
+ 'unicode-bom': 'off',
61
+ },
62
+ },
63
+ ]
64
+
65
+ return config
66
+ }
@@ -0,0 +1,20 @@
1
+ // @ts-check
2
+
3
+ // @ts-expect-error: eslint-plugin-unicorn is not typed
4
+ import plugin from 'eslint-plugin-no-only-tests'
5
+
6
+ export const noOnlyTests = () => {
7
+ /** @type {import('eslint-define-config').FlatESLintConfigItem[]} */
8
+ const config = [
9
+ {
10
+ plugins: {
11
+ 'no-only-tests': plugin,
12
+ },
13
+ rules: {
14
+ 'no-only-tests/no-only-tests': 'error',
15
+ },
16
+ },
17
+ ]
18
+
19
+ return config
20
+ }
@@ -0,0 +1,85 @@
1
+ // @ts-check
2
+
3
+ import plugin from 'eslint-plugin-jsonc'
4
+ import parser from 'jsonc-eslint-parser'
5
+
6
+ import { GLOB_PACKAGE_JSON } from './shared.js'
7
+
8
+ /**
9
+ * Sort package.json keys
10
+ */
11
+ export const packageJson = () => {
12
+ /** @type {import('eslint-define-config').FlatESLintConfigItem[]} */
13
+ const config = [
14
+ {
15
+ files: [GLOB_PACKAGE_JSON],
16
+ languageOptions: {
17
+ // @ts-expect-error: the types for `parser` seems to be wrong
18
+ parser,
19
+ parserOptions: {
20
+ jsonSyntax: 'JSON5',
21
+ },
22
+ },
23
+ plugins: {
24
+ // @ts-expect-error: incorrect types
25
+ jsonc: plugin,
26
+ },
27
+ rules: {
28
+ 'jsonc/sort-keys': [
29
+ 'warn',
30
+ {
31
+ pathPattern: '^$',
32
+ order: [
33
+ 'name',
34
+ 'displayName',
35
+ 'publisher',
36
+ 'type',
37
+ 'version',
38
+ 'private',
39
+ 'packageManager',
40
+ 'description',
41
+ 'author',
42
+ 'license',
43
+ 'funding',
44
+ 'homepage',
45
+ 'repository',
46
+ 'bugs',
47
+ 'contributes',
48
+ 'keywords',
49
+ 'categories',
50
+ 'sideEffects',
51
+ 'main',
52
+ 'module',
53
+ 'types',
54
+ 'exports',
55
+ 'typesVersions',
56
+ 'bin',
57
+ 'icon',
58
+ 'files',
59
+ 'engines',
60
+ 'scripts',
61
+ 'dependencies',
62
+ 'peerDependencies',
63
+ 'peerDependenciesMeta',
64
+ 'optionalDependencies',
65
+ 'devDependencies',
66
+ 'publishConfig',
67
+ 'overrides',
68
+ 'resolutions',
69
+ ],
70
+ },
71
+ {
72
+ pathPattern: '^(?:dev|peer|optional|bundled)?[Dd]ependencies$',
73
+ order: { type: 'asc' },
74
+ },
75
+ {
76
+ pathPattern: '^exports.*$',
77
+ order: ['types', 'require', 'import', 'default'],
78
+ },
79
+ ],
80
+ },
81
+ },
82
+ ]
83
+
84
+ return config
85
+ }
@@ -0,0 +1,20 @@
1
+ import prettierConfig from 'eslint-config-prettier'
2
+
3
+ /**
4
+ * Turns off all rules that are unnecessary or might conflict with Prettier.
5
+ *
6
+ * Notice that this config does not run `prettier` as an ESLint rule, so you
7
+ * have to run `pretter` separately for formatting.
8
+ */
9
+ export const prettier = () => {
10
+ /** @type {import('eslint-define-config').FlatESLintConfigItem[]} */
11
+ const config = [
12
+ {
13
+ rules: {
14
+ ...prettierConfig.rules,
15
+ },
16
+ },
17
+ ]
18
+
19
+ return config
20
+ }
package/src/react.js ADDED
@@ -0,0 +1,50 @@
1
+ // @ts-check
2
+
3
+ // @ts-expect-error no types
4
+ import reactPlugin from 'eslint-plugin-react'
5
+ // @ts-expect-error no types
6
+ import reactHooksPlugin from 'eslint-plugin-react-hooks'
7
+
8
+ import { GLOB_TSX } from './shared.js'
9
+
10
+ export const react = () => {
11
+ /** @type {import('eslint-define-config').FlatESLintConfigItem[]} */
12
+ const config = [
13
+ {
14
+ files: [GLOB_TSX],
15
+ plugins: {
16
+ react: reactPlugin,
17
+ },
18
+ languageOptions: {
19
+ parserOptions: {
20
+ ecmaFeatures: {
21
+ jsx: true,
22
+ },
23
+ },
24
+ },
25
+ settings: {
26
+ react: {
27
+ version: 'detect',
28
+ },
29
+ },
30
+ rules: {
31
+ ...reactPlugin.configs.recommended.rules,
32
+ 'react/prop-types': 'off',
33
+ 'react/react-in-jsx-scope': 'off',
34
+ },
35
+ },
36
+
37
+ {
38
+ files: [GLOB_TSX],
39
+ plugins: {
40
+ 'react-hooks': reactHooksPlugin,
41
+ },
42
+ rules: {
43
+ 'react-hooks/rules-of-hooks': 'error',
44
+ 'react-hooks/exhaustive-deps': 'warn',
45
+ },
46
+ },
47
+ ]
48
+
49
+ return config
50
+ }
package/src/shared.js ADDED
@@ -0,0 +1,75 @@
1
+ // @ts-check
2
+
3
+ export const GLOB_SRC_EXT = '?([mt])[jt]s?(x)'
4
+ export const GLOB_SRC = '**/*.?([mt])[jt]s?(x)'
5
+
6
+ export const GLOB_JS = '**/*.?([mt])js'
7
+ export const GLOB_JSX = '**/*.?([mt])jsx'
8
+
9
+ export const GLOB_TS = '**/*.?([mt])ts'
10
+ export const GLOB_TSX = '**/*.?([mt])tsx'
11
+
12
+ export const GLOB_STYLE = '**/*.{c,le,sc}ss'
13
+ export const GLOB_CSS = '**/*.css'
14
+ export const GLOB_LESS = '**/*.less'
15
+ export const GLOB_SCSS = '**/*.scss'
16
+
17
+ export const GLOB_JSON = '**/*.json'
18
+ export const GLOB_JSON5 = '**/*.json5'
19
+ export const GLOB_JSONC = '**/*.jsonc'
20
+
21
+ export const GLOB_PACKAGE_JSON = '**/package.json'
22
+
23
+ export const GLOB_MARKDOWN = '**/*.md'
24
+ export const GLOB_VUE = '**/*.vue'
25
+ export const GLOB_YAML = '**/*.y?(a)ml'
26
+ export const GLOB_HTML = '**/*.htm?(l)'
27
+
28
+ export const GLOB_ALL_SRC = /** @type {const} */ ([
29
+ GLOB_SRC,
30
+ GLOB_STYLE,
31
+ GLOB_JSON,
32
+ GLOB_JSON5,
33
+ GLOB_MARKDOWN,
34
+ GLOB_VUE,
35
+ GLOB_YAML,
36
+ GLOB_HTML,
37
+ ])
38
+
39
+ export const GLOB_NODE_MODULES = /** @type {const} */ ('**/node_modules')
40
+ export const GLOB_DIST = /** @type {const} */ ('**/dist')
41
+ export const GLOB_LOCKFILE = /** @type {const} */ ([
42
+ '**/package-lock.json',
43
+ '**/yarn.lock',
44
+ '**/pnpm-lock.yaml',
45
+ ])
46
+ export const GLOB_EXCLUDE = /** @type {const} */ ([
47
+ GLOB_NODE_MODULES,
48
+ GLOB_DIST,
49
+ ...GLOB_LOCKFILE,
50
+
51
+ '**/output',
52
+ '**/coverage',
53
+ '**/temp',
54
+ '**/fixtures',
55
+ '**/.vitepress/cache',
56
+ '**/.next',
57
+ '**/.nuxt',
58
+ '**/.vercel',
59
+ '**/.changeset',
60
+ '**/.idea',
61
+ '**/.output',
62
+ '**/.vite-inspect',
63
+ '**/.yalc',
64
+ '**/dist-types',
65
+
66
+ '**/CHANGELOG*.md',
67
+ '**/*.min.*',
68
+ '**/LICENSE*',
69
+ '**/__snapshots__',
70
+ ])
71
+
72
+ export const EXTENSIONS = /** @type {const} */ ['ts', 'js']
73
+ .flatMap((ext) => [ext, ext + 'x'])
74
+ .flatMap((ext) => [ext, 'm' + ext, 'c' + ext])
75
+ .flatMap((ext) => [ext, 'd.' + ext])
@@ -0,0 +1,89 @@
1
+ // @ts-check
2
+
3
+ import tsPlugin from '@typescript-eslint/eslint-plugin'
4
+ import tsParser from '@typescript-eslint/parser'
5
+
6
+ import { GLOB_JS, GLOB_JSX, GLOB_TS, GLOB_TSX } from './shared.js'
7
+
8
+ export { tsParser, tsPlugin }
9
+
10
+ /**
11
+ * @typedef {Object} TypescriptOptions
12
+ * @property {string | false} [project] - Path to tsconfig.json, defaults
13
+ * to './tsconfig.json'. You can pass `false` to disable the tsconfig.json check.
14
+ */
15
+
16
+ /**
17
+ * @param {TypescriptOptions} [options]
18
+ */
19
+ export const typescript = (options) => {
20
+ const project = options?.project ?? './tsconfig.json'
21
+
22
+ /** @type {import('eslint-define-config').FlatESLintConfigItem[]} */
23
+ const config = [
24
+ {
25
+ files: [GLOB_TS, GLOB_TSX, GLOB_JS, GLOB_JSX],
26
+ languageOptions: {
27
+ // @ts-expect-error: the types for `parser` seems to be wrong
28
+ parser: tsParser,
29
+ parserOptions: project
30
+ ? {
31
+ project,
32
+ sourceType: 'module',
33
+ ecmaVersion: 'latest',
34
+ }
35
+ : {
36
+ sourceType: 'module',
37
+ ecmaVersion: 'latest',
38
+ },
39
+ },
40
+ plugins: {
41
+ // @ts-expect-error: they just don't play very well
42
+ '@typescript-eslint': tsPlugin,
43
+ },
44
+ rules: {
45
+ ...tsPlugin.configs['eslint-recommended'].overrides?.[0].rules,
46
+ ...tsPlugin.configs['recommended'].rules,
47
+ ...(project
48
+ ? tsPlugin.configs['recommended-requiring-type-checking'].rules
49
+ : null),
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',
58
+ '@typescript-eslint/no-explicit-any': 'warn',
59
+ '@typescript-eslint/explicit-module-boundary-types': 'off',
60
+ '@typescript-eslint/no-non-null-assertion': 'off',
61
+ '@typescript-eslint/restrict-template-expressions': 'off',
62
+ '@typescript-eslint/no-unused-vars': [
63
+ 'error',
64
+ {
65
+ argsIgnorePattern: '^_',
66
+ varsIgnorePattern: '^_',
67
+ caughtErrorsIgnorePattern: '^_',
68
+ },
69
+ ],
70
+ '@typescript-eslint/no-extra-semi': 'off',
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',
78
+ },
79
+ },
80
+ {
81
+ files: ['**/*.js', '**/*.cjs'],
82
+ rules: {
83
+ '@typescript-eslint/no-var-requires': 'off',
84
+ },
85
+ },
86
+ ]
87
+
88
+ return config
89
+ }
package/src/unicorn.js ADDED
@@ -0,0 +1,69 @@
1
+ // @ts-check
2
+
3
+ // @ts-expect-error: eslint-plugin-unicorn is not typed
4
+ import plugin from 'eslint-plugin-unicorn'
5
+
6
+ export const unicorn = () => {
7
+ /** @type {import('eslint-define-config').FlatESLintConfigItem[]} */
8
+ const config = [
9
+ {
10
+ plugins: {
11
+ unicorn: plugin,
12
+ },
13
+ rules: {
14
+ // Pass error message when throwing errors
15
+ 'unicorn/error-message': 'error',
16
+ // Uppercase regex escapes
17
+ 'unicorn/escape-case': 'error',
18
+ // Array.isArray instead of instanceof
19
+ 'unicorn/no-instanceof-array': 'error',
20
+ // Prevent deprecated `new Buffer()`
21
+ 'unicorn/no-new-buffer': 'error',
22
+ // Keep regex literals safe!
23
+ 'unicorn/no-unsafe-regex': 'off',
24
+ // Lowercase number formatting for octal, hex, binary (0x1'error' instead of 0X1'error')
25
+ 'unicorn/number-literal-case': 'error',
26
+ // includes over indexOf when checking for existence
27
+ 'unicorn/prefer-includes': 'error',
28
+ // String methods startsWith/endsWith instead of more complicated stuff
29
+ 'unicorn/prefer-string-starts-ends-with': 'error',
30
+ // textContent instead of innerText
31
+ 'unicorn/prefer-text-content': 'error',
32
+ // Enforce throwing type error when throwing error while checking typeof
33
+ 'unicorn/prefer-type-error': 'error',
34
+ // Use new when throwing error
35
+ 'unicorn/throw-new-error': 'error',
36
+ // Prefer using the node: protocol
37
+ 'unicorn/prefer-node-protocol': 'error',
38
+ // Enforce explicitly comparing the length or size property of a value
39
+ 'unicorn/explicit-length-check': 'error',
40
+ // Prefer `.flatMap(…)` over `.map(…).flat()`
41
+ 'unicorn/prefer-array-index-of': 'error',
42
+ // Improve regexes
43
+ 'unicorn/better-regex': 'error',
44
+ // Enforce combining multiple `Array#push()` into one call.
45
+ 'unicorn/no-array-push-push': 'warn',
46
+ // Do not use a `for` loop that can be replaced with a `for-of` loop.
47
+ 'unicorn/no-for-loop': 'error',
48
+ // Prefer `.addEventListener()` and `.removeEventListener()` over `on`-functions.
49
+ 'unicorn/prefer-add-event-listener': 'error',
50
+ // Prefer `.find(…)` and `.findLast(…)` over the first or last element from
51
+ 'unicorn/prefer-array-find': 'error',
52
+ // Prefer `.flatMap(…)` over `.map(…).flat()`.
53
+ 'unicorn/prefer-array-flat-map': 'error',
54
+ // Prefer `.some(…)` over `.filter(…).length` check
55
+ 'unicorn/prefer-array-some': 'error',
56
+ // Prefer `KeyboardEvent#key` over `KeyboardEvent#keyCode`
57
+ 'unicorn/prefer-keyboard-event-key': 'error',
58
+ // Enforce the use of `Math.trunc` instead of bitwise operators.
59
+ 'unicorn/prefer-math-trunc': 'error',
60
+ // Prefer negative index over `.length - index` when possible
61
+ 'unicorn/prefer-negative-index': 'error',
62
+ // Prefer `Number` static properties over global ones.
63
+ 'unicorn/prefer-number-properties': 'warn',
64
+ },
65
+ },
66
+ ]
67
+
68
+ return config
69
+ }
package/CHANGELOG.md DELETED
@@ -1,85 +0,0 @@
1
- # Changelog
2
-
3
- ### Dependencies
4
-
5
- * The following workspace dependencies were updated
6
- * dependencies
7
- * @ocavue/eslint-config-basic bumped from ^0.4.0 to ^0.5.0
8
- * @ocavue/eslint-config-prettier bumped from ^0.4.0 to ^0.4.1
9
-
10
- ### Dependencies
11
-
12
- * The following workspace dependencies were updated
13
- * dependencies
14
- * @ocavue/eslint-config-basic bumped from ^0.5.0 to ^0.6.0
15
-
16
- ### Dependencies
17
-
18
- * The following workspace dependencies were updated
19
- * dependencies
20
- * @ocavue/eslint-config-basic bumped from ^0.6.0 to ^0.6.1
21
-
22
- ### Dependencies
23
-
24
- * The following workspace dependencies were updated
25
- * dependencies
26
- * @ocavue/eslint-config-basic bumped from ^0.6.2 to ^0.6.3
27
-
28
- ## [0.4.7](https://github.com/ocavue/eslint-config/compare/eslint-config-v0.4.6...eslint-config-v0.4.7) (2023-01-15)
29
-
30
-
31
- ### Bug Fixes
32
-
33
- * correct the repository link in package.json ([#10](https://github.com/ocavue/eslint-config/issues/10)) ([4b5ad5e](https://github.com/ocavue/eslint-config/commit/4b5ad5e40459c470abb8fda326b76730f270d4a1))
34
-
35
-
36
- ### Dependencies
37
-
38
- * The following workspace dependencies were updated
39
- * dependencies
40
- * @ocavue/eslint-config-basic bumped from ^0.6.4 to ^0.6.5
41
- * @ocavue/eslint-config-prettier bumped from ^0.4.2 to ^0.4.3
42
-
43
- ## [0.4.6](https://github.com/ocavue/eslint-config/compare/eslint-config-v0.4.5...eslint-config-v0.4.6) (2023-01-09)
44
-
45
-
46
- ### Bug Fixes
47
-
48
- * update dependencies ([b1c1738](https://github.com/ocavue/eslint-config/commit/b1c17382b337a31564b627776a44b6048efcfd6f))
49
-
50
-
51
- ### Dependencies
52
-
53
- * The following workspace dependencies were updated
54
- * dependencies
55
- * @ocavue/eslint-config-basic bumped from ^0.6.3 to ^0.6.4
56
- * @ocavue/eslint-config-prettier bumped from ^0.4.1 to ^0.4.2
57
-
58
- ## [0.4.4](https://github.com/ocavue/eslint-config/compare/eslint-config-v0.4.3...eslint-config-v0.4.4) (2022-11-23)
59
-
60
-
61
- ### Bug Fixes
62
-
63
- * add missing dependencies ([70eaaa5](https://github.com/ocavue/eslint-config/commit/70eaaa50bb482ce3bd3575deb5e7b0011b417c7b))
64
-
65
-
66
- ### Dependencies
67
-
68
- * The following workspace dependencies were updated
69
- * dependencies
70
- * @ocavue/eslint-config-basic bumped from ^0.6.1 to ^0.6.2
71
-
72
- ## [0.4.0](https://github.com/ocavue/eslint-config/compare/eslint-config-v0.3.0...eslint-config-v0.4.0) (2022-11-23)
73
-
74
-
75
- ### Features
76
-
77
- * release packages ([247817b](https://github.com/ocavue/eslint-config/commit/247817b1397b6291b5c800435a23748075d535f7))
78
-
79
-
80
- ### Dependencies
81
-
82
- * The following workspace dependencies were updated
83
- * dependencies
84
- * @ocavue/eslint-config-basic bumped from ^0.2.1 to ^0.4.0
85
- * @ocavue/eslint-config-prettier bumped from ^0.2.1 to ^0.4.0