@kitschpatrol/eslint-config 2.0.0 → 2.1.1

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/bin/cli.js ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ import F from"chalk";import{execa as x}from"execa";import O from"meow";import d from"node:path";import{Transform as A}from"node:stream";import{fileURLToPath as S}from"node:url";import{packageUp as k}from"package-up";function $(o,t){return new A({transform(n,e,i){let m=n.toString().split(/\r?\n/).filter(l=>l.trim().length>0).map(l=>`${o?F[t]("["+o+"] "):""}${l}`).join(`
3
+ `)+`
4
+ `;this.push(m),i()}})}function N(o,t){let n=`
5
+ Usage
6
+ $ ${o} [<file|glob> ...]
7
+ `;if(Object.keys(t).length>0){n+=`
8
+ Options`;for(let e of Object.keys(t))switch(e){case"init":{n+=`
9
+ --init, -i Initialize by copying starter config files to your project root.`;break}case"check":{n+=`
10
+ --check, -c Check for and report issues. Same as ${o}.`;break}case"fix":{n+=`
11
+ --fix, -f Fix all auto-fixable issues, and report the un-fixable.`;break}case"printConfig":{n+=`
12
+ --print-config <file> Print the effective configuration for a file`;break}default:console.error(`Unknown command name: ${e}`)}}return n}function j(o){return Object.keys(o).reduce((t,n)=>{let e={};switch(n){case"init":{e={shortFlag:"i",type:"boolean"};break}case"check":{e={aliases:["lint",""],shortFlag:"l",type:"boolean"};break}case"fix":{e={shortFlag:"f",type:"boolean"};break}case"printConfig":{e={type:"boolean"};break}default:console.error(`Unknown command name: ${n}`)}return t[n]=e,t},{})}async function y(o,t,n=[]){if(t.command!==void 0&&typeof t.command=="string"){let e;try{let i=x(t.command,[...t.options??[],...n],{env:{FORCE_COLOR:"true"},stdin:"inherit"});i.stdout?.pipe(o,{end:!1}),i.stderr?.pipe(o,{end:!1}),await i,e=i.exitCode??1}catch(i){e=typeof i.exitCode=="number"?i.exitCode:1}return e}return o.write(`Error: Invalid optionCommand: ${JSON.stringify(t,void 0,2)}`),1}function h(o,t,n){o.length===0&&!t.defaultArguments&&(n.write(`Error: This command must be used with a file argument
13
+ `),process.exit(1))}async function C(o,t,n,e){let i=O(N(o,e),{allowUnknownFlags:!1,booleanDefault:void 0,flags:j(e),importMeta:import.meta}),{flags:u,input:m}=i,l=Object.keys(e).reduce((c,r)=>(u[r]&&(c[r]=e[r]),c),{});Object.keys(l).length===0&&(l.check=e.check);let s=$(t,n);s.pipe(process.stdout);let a=0;for(let[c,r]of Object.entries(l))if(typeof r.command=="function"){h(m,r,s);let f=m.length===0?r.defaultArguments??[]:m,g=r.options??[];a+=await r.command(s,f,g)}else if(typeof r.command=="string")h(m,r,s),a+=await y(s,r,m.length===0?r.defaultArguments:m);else switch(c){case"init":{let f=await k();if(f===void 0){s.write("Error: The `--init` flag must be used in a directory with a package.json file\n"),a+=1;break}let g=await k({cwd:S(import.meta.url)});if(g===void 0){s.write(`Error: The script being called was not in a package, weird.
14
+ `),a+=1;break}let p=d.join(d.dirname(g),"init/"),b=d.dirname(f);s.write(`Copying initial configuration files from:
15
+ "${p}" \u2192 "${b}"
16
+ `);let w={command:"cp",options:["-Ri",`${p}`,`${b}`]};a+=await y(s,w);break}case"check":{console.error("No default implementation for check"),a+=1;break}case"fix":{console.error("No default implementation for fix"),a+=1;break}case"printConfig":{console.error("No default implementation for print-config"),a+=1;break}default:{console.error(`Unknown command name: ${c}`),a+=1;break}}process.exit(a>0?1:0)}await C("eslint-config","ESLint","magenta",{check:{command:"eslint",defaultArguments:["."]},fix:{command:"eslint",defaultArguments:["."],options:["--fix"]},init:{},printConfig:{command:"eslint",options:["--print-config"]}});
@@ -1,4 +1,3 @@
1
- // eslint-disable-next-line no-undef
2
1
  module.exports = {
3
2
  extends: ['@kitschpatrol/eslint-config'],
4
3
  };
package/main.cjs CHANGED
@@ -1,23 +1,59 @@
1
- // eslint-disable-next-line no-undef
2
1
  /* @type {import('eslint').Linter.Config} */
2
+
3
+ const extendsPrefix = [
4
+ 'eslint:recommended',
5
+ 'plugin:n/recommended',
6
+ 'plugin:unicorn/recommended',
7
+ 'xo',
8
+ 'plugin:perfectionist/recommended-natural',
9
+ ];
10
+
11
+ const extendsSuffix = ['prettier'];
12
+
13
+ const rulesConfig = {
14
+ // Possible perfectionist conflicts
15
+ '@typescript-eslint/adjacent-overload-signatures': 'off',
16
+ '@typescript-eslint/sort-type-constituents': 'off',
17
+ 'import/order': 'off',
18
+ 'n/no-process-exit': 'off', // Duplicated in unicorn
19
+ 'no-await-in-loop': 'off',
20
+ 'no-warning-comments': 'off',
21
+ 'perfectionist/sort-imports': [
22
+ 'error',
23
+ {
24
+ 'newlines-between': 'never',
25
+ },
26
+ ],
27
+ 'react/jsx-sort-props': 'off',
28
+ 'sort-imports': 'off',
29
+ 'unicorn/no-array-reduce': 'off',
30
+ 'unicorn/prevent-abbreviations': [
31
+ 'error',
32
+ {
33
+ allowList: {
34
+ Props: true,
35
+ acc: true,
36
+ args: true,
37
+ props: true,
38
+ },
39
+ },
40
+ ],
41
+ };
42
+
3
43
  module.exports = {
4
44
  env: {
5
45
  browser: true,
6
46
  node: true,
7
47
  },
8
- extends: [
9
- 'eslint:recommended',
10
- 'plugin:@typescript-eslint/recommended',
11
- 'plugin:@typescript-eslint/recommended',
12
- 'plugin:astro/recommended',
13
- 'plugin:astro/jsx-a11y-recommended',
14
- 'plugin:svelte/recommended',
15
- 'plugin:unicorn/recommended',
16
- 'prettier',
17
- 'plugin:perfectionist/recommended-natural',
18
- ],
48
+ extends: [...extendsPrefix, ...extendsSuffix],
19
49
  overrides: [
20
50
  {
51
+ extends: [...extendsPrefix, 'plugin:@typescript-eslint/recommended', 'xo-typescript', ...extendsSuffix],
52
+ files: ['*.ts', '*.tsx', '*.mts', '*.cts'],
53
+ rules: rulesConfig,
54
+ },
55
+ {
56
+ extends: [...extendsPrefix, 'plugin:svelte/recommended', 'xo-typescript', ...extendsSuffix],
21
57
  files: ['*.astro'],
22
58
  parser: 'astro-eslint-parser',
23
59
  parserOptions: {
@@ -25,6 +61,7 @@ module.exports = {
25
61
  parser: '@typescript-eslint/parser',
26
62
  },
27
63
  rules: {
64
+ ...rulesConfig,
28
65
  'no-unused-vars': [
29
66
  'error',
30
67
  {
@@ -32,47 +69,34 @@ module.exports = {
32
69
  destructuredArrayIgnorePattern: '^_',
33
70
  },
34
71
  ],
72
+ // Todo enforce capitalization?
35
73
  'unicorn/filename-case': 'off',
36
74
  },
37
75
  },
38
76
  {
77
+ extends: [
78
+ ...extendsPrefix,
79
+ 'plugin:astro/recommended',
80
+ 'plugin:astro/jsx-a11y-recommended',
81
+ 'plugin:@typescript-eslint/recommended',
82
+ 'xo-typescript',
83
+ ...extendsSuffix,
84
+ ],
39
85
  files: ['*.svelte'],
40
86
  parser: 'svelte-eslint-parser',
41
87
  parserOptions: {
42
88
  parser: '@typescript-eslint/parser',
43
89
  },
44
90
  rules: {
91
+ ...rulesConfig,
45
92
  // https://github.com/nuxt/eslint-config/issues/140
46
93
  '@typescript-eslint/ban-types': 'off',
47
94
  // https://github.com/typescript-eslint/typescript-eslint/blob/1cf9243/docs/getting-started/linting/FAQ.md#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
48
95
  'no-undef': 'off',
96
+ // Todo enforce capitalization?
49
97
  'unicorn/filename-case': 'off',
50
98
  },
51
99
  },
52
100
  ],
53
- rules: {
54
- // possible perfectionist conflicts
55
- '@typescript-eslint/adjacent-overload-signatures': 'off',
56
- '@typescript-eslint/sort-type-constituents': 'off',
57
- 'import/order': 'off',
58
- 'perfectionist/sort-imports': [
59
- 'error',
60
- {
61
- 'newlines-between': 'never',
62
- },
63
- ],
64
- 'react/jsx-sort-props': 'off',
65
- 'sort-imports': 'off',
66
- 'unicorn/no-array-reduce': 'off',
67
- 'unicorn/prevent-abbreviations': [
68
- 'error',
69
- {
70
- allowList: {
71
- Props: true,
72
- props: true,
73
- args: true,
74
- },
75
- },
76
- ],
77
- },
101
+ rules: rulesConfig,
78
102
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitschpatrol/eslint-config",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "type": "module",
5
5
  "description": "Eslint config for @kitschpatrol/shared-config",
6
6
  "repository": {
@@ -23,26 +23,39 @@
23
23
  "pnpm": ">=8.0.0"
24
24
  },
25
25
  "bin": {
26
- "eslint-config": "./cli.js"
26
+ "eslint-config": "bin/cli.js"
27
27
  },
28
- "main": "main.cjs",
28
+ "main": "./main.cjs",
29
+ "files": [
30
+ "bin",
31
+ "init"
32
+ ],
29
33
  "peerDependencies": {
30
34
  "eslint": ">=8.52.0"
31
35
  },
32
36
  "dependencies": {
33
- "@typescript-eslint/eslint-plugin": "^6.13.2",
34
- "@typescript-eslint/parser": "^6.13.2",
37
+ "@typescript-eslint/eslint-plugin": "^6.14.0",
38
+ "@typescript-eslint/parser": "^6.14.0",
35
39
  "astro-eslint-parser": "^0.16.0",
40
+ "chalk": "^5.3.0",
36
41
  "eslint-config-prettier": "^9.1.0",
42
+ "eslint-config-xo": "^0.43.1",
43
+ "eslint-config-xo-typescript": "^1.0.1",
37
44
  "eslint-plugin-astro": "^0.30.0",
38
45
  "eslint-plugin-jsx-a11y": "^6.8.0",
46
+ "eslint-plugin-n": "^16.4.0",
39
47
  "eslint-plugin-perfectionist": "^2.5.0",
40
48
  "eslint-plugin-svelte": "^2.35.1",
41
49
  "eslint-plugin-unicorn": "^49.0.0",
42
- "minimist": "^1.2.8",
43
- "zx": "^7.2.3"
50
+ "execa": "^8.0.1",
51
+ "meow": "^12.1.1",
52
+ "package-up": "^5.0.0"
44
53
  },
45
54
  "publishConfig": {
46
55
  "access": "public"
56
+ },
57
+ "scripts": {
58
+ "build": "../../scripts/build.ts",
59
+ "cli": "node ./bin/cli.js"
47
60
  }
48
61
  }
package/cli.js DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env zx
2
- /* eslint-disable unicorn/prefer-module */
3
- import minimist from 'minimist';
4
- import { $, path } from 'zx';
5
- import 'zx/globals';
6
-
7
- async function main() {
8
- const options = ['init', 'fix', 'check'];
9
- const args = minimist(process.argv.slice(2), {
10
- boolean: options,
11
- });
12
-
13
- const argumentCount = options.reduce((count, argument) => count + (args[argument] ? 1 : 0), 0);
14
- if (argumentCount !== 1) {
15
- console.error(`[ESLint] Please provide exactly one of ${options.map((opt) => `--${opt}`).join(' or ')}`);
16
- process.exit(1);
17
- }
18
-
19
- process.env.FORCE_COLOR = '1';
20
- if (args.init) {
21
- await $`cp -Ri ${path.join(__dirname, 'init')}/. ${process.cwd()}`.nothrow();
22
- } else if (args.fix) {
23
- await $`eslint --fix .`;
24
- } else if (args.check) {
25
- await $`eslint .`;
26
- }
27
- }
28
-
29
- await main();