@coderwyd/eslint-config 1.0.10 → 1.1.0-beta.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 ADDED
@@ -0,0 +1,132 @@
1
+ # @coderwyd/eslint-config
2
+
3
+ [![release status](https://github.com/coderwyd/eslint-config/actions/workflows/release.yml/badge.svg)](https://github.com/coderwyd/eslint-config/actions/workflows/release.yml)
4
+ [![npm](https://img.shields.io/npm/v/@coderwyd/eslint-config.svg)](https://npmjs.org/package/@coderwyd/eslint-config)
5
+ [![downloads](https://img.shields.io/npm/dm/@coderwyd/eslint-config.svg)](https://npmjs.org/package/@coderwyd/eslint-config)
6
+
7
+ ## Feature
8
+
9
+ - Single quotes, no semi
10
+ - Auto fix for formatting (aimed to be used standalone **without** Prettier)
11
+ - Designed to work with TypeScript, Vue out-of-box
12
+ - Lint also for json, yaml, markdown
13
+ - Sorted imports, dangling commas
14
+ - Reasonable defaults, best practices, only one-line of config
15
+
16
+ ## Usage
17
+
18
+ ### Install
19
+
20
+ ```bash
21
+ pnpm add -D eslint @coderwyd/eslint-config # JavaScript, TypeScript and Vue 3
22
+ # Or yarn add eslint @coderwyd/eslint-config -D / npm install eslint @coderwyd/eslint-config -D
23
+ pnpm add -D @coderwyd/eslint-config-basic # JavaScript only
24
+ pnpm add -D @coderwyd/eslint-config-ts # JavaScript and TypeScript
25
+ pnpm add -D @coderwyd/eslint-config-react # JavaScript, TypeScript and React
26
+ pnpm add -D @coderwyd/eslint-config-vue # JavaScript, TypeScript and Vue 3
27
+ ```
28
+
29
+ ### Config `.eslintrc`
30
+
31
+ ```json
32
+ {
33
+ "extends": "@coderwyd"
34
+ }
35
+ ```
36
+
37
+ > You don't need `.eslintignore` normally as it has been provided by the preset.
38
+
39
+ ### Add script for package.json
40
+
41
+ For example:
42
+
43
+ ```json
44
+ {
45
+ "scripts": {
46
+ "lint": "eslint .",
47
+ "lint:fix": "eslint . --fix"
48
+ }
49
+ }
50
+ ```
51
+
52
+ ### VS Code support (auto fix)
53
+
54
+ Add the following settings to your `settings.json`:
55
+
56
+ ```jsonc
57
+ {
58
+ "prettier.enable": false,
59
+ "editor.formatOnSave": false,
60
+ "editor.codeActionsOnSave": {
61
+ "source.fixAll.eslint": true,
62
+ "source.organizeImports": false
63
+ },
64
+
65
+ // The following is optional.
66
+ // It's better to put under project setting `.vscode/settings.json`
67
+ // to avoid conflicts with working with different eslint configs
68
+ // that does not support all formats.
69
+ "eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact", "vue", "html", "markdown", "json", "jsonc", "yaml"]
70
+ }
71
+ ```
72
+
73
+ ### TypeScript Aware Rules
74
+
75
+ Type aware rules are enabled when a `tsconfig.eslint.json` is found in the project root, which will introduce some stricter rules into your project. If you want to enable it while have no `tsconfig.eslint.json` in the project root, you can change tsconfig name by modifying `ESLINT_TSCONFIG` env.
76
+
77
+ ```js
78
+ // .eslintrc.js
79
+ const process = require('node:process')
80
+
81
+ process.env.ESLINT_TSCONFIG = 'tsconfig.json'
82
+
83
+ module.exports = {
84
+ extends: '@coderwyd',
85
+ }
86
+ ```
87
+
88
+ ### Lint Staged
89
+
90
+ If you want to apply lint and auto-fix before every commit, you can add the following to your `package.json`:
91
+
92
+ ```json
93
+ {
94
+ "simple-git-hooks": {
95
+ "pre-commit": "pnpm lint-staged"
96
+ },
97
+ "lint-staged": {
98
+ "*": "eslint --fix"
99
+ }
100
+ }
101
+ ```
102
+
103
+ and then
104
+
105
+ ```bash
106
+ npm i -D lint-staged simple-git-hooks
107
+ ```
108
+
109
+ ## FAQ
110
+
111
+ ### Customization rules
112
+
113
+ add you like rules to your .eslintrc file.
114
+
115
+ <!-- eslint-skip -->
116
+
117
+ ```jsonc
118
+ {
119
+ "extends": "@coderwyd",
120
+ "rules": {
121
+ // your rules...
122
+ }
123
+ }
124
+ ```
125
+
126
+ ## Thanks
127
+
128
+ This project is based on [@antfu/eslint-config](https://github.com/antfu/eslint-config)
129
+
130
+ ## License
131
+
132
+ [MIT](./LICENSE) License &copy; 2019-PRESENT [Donny Wang](https://github.com/coderwyd)
@@ -0,0 +1,154 @@
1
+ import { FlatESLintConfigItem } from 'eslint-define-config';
2
+ export { default as pluginAntfu } from 'eslint-plugin-antfu';
3
+ export { default as pluginComments } from 'eslint-plugin-eslint-comments';
4
+ export { default as pluginImport } from 'eslint-plugin-i';
5
+ export { default as pluginJsdoc } from 'eslint-plugin-jsdoc';
6
+ export { default as pluginJsonc } from 'eslint-plugin-jsonc';
7
+ export { default as pluginMarkdown } from 'eslint-plugin-markdown';
8
+ export { default as pluginNode } from 'eslint-plugin-n';
9
+ export { default as pluginStylisticJs } from '@stylistic/eslint-plugin-js';
10
+ export { default as pluginStylisticTs } from '@stylistic/eslint-plugin-ts';
11
+ export { default as pluginTs } from '@typescript-eslint/eslint-plugin';
12
+ export { default as pluginUnicorn } from 'eslint-plugin-unicorn';
13
+ export { default as pluginUnusedImports } from 'eslint-plugin-unused-imports';
14
+ export { default as pluginVue } from 'eslint-plugin-vue';
15
+ export { default as pluginYml } from 'eslint-plugin-yml';
16
+ export { default as pluginNoOnlyTests } from 'eslint-plugin-no-only-tests';
17
+ export { default as pluginReact } from 'eslint-plugin-react';
18
+ export { default as pluginReactHooks } from 'eslint-plugin-react-hooks';
19
+ export { default as parserTs } from '@typescript-eslint/parser';
20
+ export { default as parserVue } from 'vue-eslint-parser';
21
+ export { default as parserYml } from 'yaml-eslint-parser';
22
+ export { default as parserJsonc } from 'jsonc-eslint-parser';
23
+
24
+ interface OptionsComponentExts {
25
+ /**
26
+ * Additional extensions for components.
27
+ *
28
+ * @example ['vue']
29
+ * @default []
30
+ */
31
+ componentExts?: string[];
32
+ }
33
+ interface OptionsTypeScriptWithLanguageServer {
34
+ tsconfigPath: string;
35
+ tsconfigRootDir?: string;
36
+ }
37
+ interface OptionsHasTypeScript {
38
+ typescript?: boolean;
39
+ }
40
+ interface OptionsIsInEditor {
41
+ isInEditor?: boolean;
42
+ }
43
+ interface OptionsConfig {
44
+ /**
45
+ * Enable TypeScript support.
46
+ *
47
+ * Passing an object to enable TypeScript Language Server support.
48
+ *
49
+ * @default auto-detect based on the dependencies
50
+ */
51
+ typescript?: boolean | OptionsTypeScriptWithLanguageServer;
52
+ /**
53
+ * Enable test support.
54
+ *
55
+ * @default true
56
+ */
57
+ test?: boolean;
58
+ /**
59
+ * Enable Vue support.
60
+ *
61
+ * @default auto-detect based on the dependencies
62
+ */
63
+ vue?: boolean;
64
+ /**
65
+ * Enable JSONC support.
66
+ *
67
+ * @default true
68
+ */
69
+ jsonc?: boolean;
70
+ /**
71
+ * Enable YAML support.
72
+ *
73
+ * @default true
74
+ */
75
+ yaml?: boolean;
76
+ /**
77
+ * Enable Markdown support.
78
+ *
79
+ * @default true
80
+ */
81
+ markdown?: boolean;
82
+ /**
83
+ * Enable stylistic rules.
84
+ *
85
+ * @default true
86
+ */
87
+ stylistic?: boolean;
88
+ /**
89
+ * Control to disable some rules in editors.
90
+ * @default auto-detect based on the process.env
91
+ */
92
+ isInEditor?: boolean;
93
+ }
94
+
95
+ /**
96
+ * Construct an array of ESLint flat config items.
97
+ */
98
+ declare function coderwyd(options?: OptionsConfig, ...userConfigs: (FlatESLintConfigItem | FlatESLintConfigItem[])[]): FlatESLintConfigItem[];
99
+
100
+ declare const comments: FlatESLintConfigItem[];
101
+
102
+ declare const ignores: FlatESLintConfigItem[];
103
+
104
+ declare const imports: FlatESLintConfigItem[];
105
+
106
+ declare function javascript(options?: OptionsIsInEditor): FlatESLintConfigItem[];
107
+
108
+ declare const jsdoc: FlatESLintConfigItem[];
109
+
110
+ declare const jsonc: FlatESLintConfigItem[];
111
+
112
+ declare function markdown(options?: OptionsComponentExts): FlatESLintConfigItem[];
113
+
114
+ declare const node: FlatESLintConfigItem[];
115
+
116
+ /**
117
+ * Sort package.json
118
+ *
119
+ * Requires `jsonc` config
120
+ */
121
+ declare const sortPackageJson: FlatESLintConfigItem[];
122
+ /**
123
+ * Sort tsconfig.json
124
+ *
125
+ * Requires `jsonc` config
126
+ */
127
+ declare const sortTsconfig: FlatESLintConfigItem[];
128
+
129
+ declare const javascriptStylistic: FlatESLintConfigItem[];
130
+ declare const typescriptStylistic: FlatESLintConfigItem[];
131
+
132
+ declare function typescript(options?: OptionsComponentExts): FlatESLintConfigItem[];
133
+ declare function typescriptWithLanguageServer(options: OptionsTypeScriptWithLanguageServer & OptionsComponentExts): FlatESLintConfigItem[];
134
+
135
+ declare const unicorn: FlatESLintConfigItem[];
136
+
137
+ declare function getVueVersion(): number;
138
+ declare function vue(options?: OptionsHasTypeScript): FlatESLintConfigItem[];
139
+
140
+ declare const yml: FlatESLintConfigItem[];
141
+
142
+ declare function test(options?: OptionsIsInEditor): FlatESLintConfigItem[];
143
+
144
+ declare function react(options?: OptionsHasTypeScript): FlatESLintConfigItem[];
145
+
146
+ /**
147
+ * Combine array and non-array configs into a single array.
148
+ */
149
+ declare function combine(...configs: (FlatESLintConfigItem | FlatESLintConfigItem[])[]): FlatESLintConfigItem[];
150
+ declare function renameRules(rules: Record<string, any>, from: string, to: string): {
151
+ [k: string]: any;
152
+ };
153
+
154
+ export { OptionsComponentExts, OptionsConfig, OptionsHasTypeScript, OptionsIsInEditor, OptionsTypeScriptWithLanguageServer, coderwyd, combine, comments, coderwyd as default, getVueVersion, ignores, imports, javascript, javascriptStylistic, jsdoc, jsonc, markdown, node, react, renameRules, sortPackageJson, sortTsconfig, test, typescript, typescriptStylistic, typescriptWithLanguageServer, unicorn, vue, yml };