@xsynaptic/eslint-config 3.5.0 → 3.6.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/dist/index.d.mts CHANGED
@@ -1,11 +1,20 @@
1
1
  import { Config, ConfigWithExtends, ConfigWithExtendsArray } from "@eslint/config-helpers";
2
2
 
3
3
  //#region src/index.d.ts
4
+ type RestrictedSyntaxOption = string | {
5
+ message?: string;
6
+ selector: string;
7
+ };
8
+ declare const restrictedSyntaxDefaults: Array<RestrictedSyntaxOption>;
9
+ declare function getAstroConfig(options?: {
10
+ a11y?: ConfigWithExtendsArray;
11
+ }): ConfigWithExtendsArray;
4
12
  declare function getConfig(customConfig?: ConfigWithExtendsArray, options?: {
5
13
  customGlobals?: Record<string, 'readonly' | 'writeable'>;
6
14
  parserOptions?: NonNullable<Config['languageOptions']>['parserOptions'];
15
+ restrictedSyntax?: Array<RestrictedSyntaxOption>;
7
16
  }): ConfigWithExtendsArray;
8
17
  declare function getWebComponentConfig(files: Array<string>): ConfigWithExtends;
9
18
  //#endregion
10
- export { getConfig, getWebComponentConfig };
19
+ export { getAstroConfig, getConfig, getWebComponentConfig, restrictedSyntaxDefaults };
11
20
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -1,13 +1,51 @@
1
1
  import { defineConfig } from "@eslint/config-helpers";
2
2
  import eslint from "@eslint/js";
3
+ import astroPlugin from "eslint-plugin-astro";
3
4
  import perfectionist from "eslint-plugin-perfectionist";
4
5
  import unicornPlugin from "eslint-plugin-unicorn";
5
6
  import { configs } from "eslint-plugin-wc";
6
7
  import globals from "globals";
7
8
  import tseslint from "typescript-eslint";
8
9
  //#region src/index.ts
10
+ const restrictedSyntaxDefaults = [{
11
+ message: "Separate type imports into their own `import type` statement.",
12
+ selector: "ImportDeclaration[importKind=\"value\"] ImportSpecifier[importKind=\"type\"]"
13
+ }, {
14
+ message: "Use a ternary returning undefined (condition ? <Element /> : undefined) instead of && for conditional rendering.",
15
+ selector: ":matches(JSXElement, JSXFragment) > JSXExpressionContainer > LogicalExpression[operator=\"&&\"]"
16
+ }];
17
+ function getAstroConfig(options) {
18
+ return [
19
+ ...astroPlugin.configs["flat/recommended"],
20
+ ...options?.a11y ?? [],
21
+ {
22
+ files: ["**/*.astro"],
23
+ languageOptions: { parserOptions: {
24
+ extraFileExtensions: [".astro"],
25
+ parser: tseslint.parser
26
+ } }
27
+ },
28
+ {
29
+ files: ["**/*.astro"],
30
+ ...tseslint.configs.disableTypeChecked
31
+ },
32
+ {
33
+ files: ["**/*.astro/*.ts", "*.astro/*.ts"],
34
+ ...tseslint.configs.disableTypeChecked
35
+ },
36
+ {
37
+ files: [
38
+ "**/*.js",
39
+ "**/*.mjs",
40
+ "**/*.cjs"
41
+ ],
42
+ ...tseslint.configs.disableTypeChecked
43
+ }
44
+ ];
45
+ }
9
46
  function getConfig(customConfig, options) {
10
47
  const customGlobals = options?.customGlobals ?? {};
48
+ const restrictedSyntax = [...restrictedSyntaxDefaults, ...options?.restrictedSyntax ?? []];
11
49
  return defineConfig(...[
12
50
  eslint.configs.recommended,
13
51
  ...tseslint.configs.strictTypeChecked,
@@ -38,10 +76,7 @@ function getConfig(customConfig, options) {
38
76
  varsIgnorePattern: "^_"
39
77
  }],
40
78
  "@typescript-eslint/prefer-nullish-coalescing": "off",
41
- "no-restricted-syntax": ["error", {
42
- message: "Separate type imports into their own `import type` statement.",
43
- selector: "ImportDeclaration[importKind=\"value\"] ImportSpecifier[importKind=\"type\"]"
44
- }]
79
+ "no-restricted-syntax": ["error", ...restrictedSyntax]
45
80
  }
46
81
  },
47
82
  unicornPlugin.configs.recommended,
@@ -72,6 +107,6 @@ function getWebComponentConfig(files) {
72
107
  };
73
108
  }
74
109
  //#endregion
75
- export { getConfig, getWebComponentConfig };
110
+ export { getAstroConfig, getConfig, getWebComponentConfig, restrictedSyntaxDefaults };
76
111
 
77
112
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["webComponentConfigs"],"sources":["../src/index.ts"],"sourcesContent":["import type { Config, ConfigWithExtends, ConfigWithExtendsArray } from '@eslint/config-helpers';\n\nimport { defineConfig } from '@eslint/config-helpers';\nimport eslint from '@eslint/js';\nimport perfectionist from 'eslint-plugin-perfectionist';\nimport unicornPlugin from 'eslint-plugin-unicorn';\nimport { configs as webComponentConfigs } from 'eslint-plugin-wc';\nimport globals from 'globals';\nimport tseslint from 'typescript-eslint';\n\nexport function getConfig(\n\tcustomConfig?: ConfigWithExtendsArray,\n\toptions?: {\n\t\tcustomGlobals?: Record<string, 'readonly' | 'writeable'>;\n\t\tparserOptions?: NonNullable<Config['languageOptions']>['parserOptions'];\n\t},\n): ConfigWithExtendsArray {\n\tconst customGlobals = options?.customGlobals ?? {};\n\n\tconst baseConfig = [\n\t\teslint.configs.recommended,\n\t\t...tseslint.configs.strictTypeChecked,\n\t\t...tseslint.configs.stylisticTypeChecked,\n\t\t{\n\t\t\tlanguageOptions: {\n\t\t\t\tglobals: {\n\t\t\t\t\t...globals.builtin,\n\t\t\t\t\t...globals.nodeBuiltin,\n\t\t\t\t\t...customGlobals,\n\t\t\t\t},\n\t\t\t\tparser: tseslint.parser,\n\t\t\t\tparserOptions: options?.parserOptions ?? {\n\t\t\t\t\tprojectService: true,\n\t\t\t\t},\n\t\t\t},\n\t\t\tplugins: {\n\t\t\t\t'@typescript-eslint': tseslint.plugin,\n\t\t\t},\n\t\t\trules: {\n\t\t\t\t'@typescript-eslint/array-type': ['warn', { default: 'generic' }],\n\t\t\t\t'@typescript-eslint/consistent-type-imports': [\n\t\t\t\t\t'error',\n\t\t\t\t\t{ fixStyle: 'separate-type-imports', prefer: 'type-imports' },\n\t\t\t\t],\n\t\t\t\t'@typescript-eslint/no-non-null-assertion': 'off',\n\t\t\t\t'@typescript-eslint/no-unused-vars': [\n\t\t\t\t\t'error',\n\t\t\t\t\t{\n\t\t\t\t\t\targsIgnorePattern: '^_',\n\t\t\t\t\t\tcaughtErrorsIgnorePattern: '^_',\n\t\t\t\t\t\tdestructuredArrayIgnorePattern: '^_',\n\t\t\t\t\t\tignoreRestSiblings: true,\n\t\t\t\t\t\tvarsIgnorePattern: '^_',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\t'@typescript-eslint/prefer-nullish-coalescing': 'off',\n\t\t\t\t'no-restricted-syntax': [\n\t\t\t\t\t'error',\n\t\t\t\t\t{\n\t\t\t\t\t\tmessage: 'Separate type imports into their own `import type` statement.',\n\t\t\t\t\t\tselector: 'ImportDeclaration[importKind=\"value\"] ImportSpecifier[importKind=\"type\"]',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tunicornPlugin.configs.recommended,\n\t\t{\n\t\t\trules: {\n\t\t\t\t'unicorn/filename-case': 'warn',\n\t\t\t\t'unicorn/no-array-callback-reference': 'off', // I prefer this pattern for filtering/sorting content\n\t\t\t\t'unicorn/number-literal-case': ['error', { hexadecimalValue: 'lowercase' }], // Lowercase hex to match Prettier\n\t\t\t\t'unicorn/prevent-abbreviations': 'off', // I *like* abbreviations!\n\t\t\t},\n\t\t},\n\t\tperfectionist.configs['recommended-natural'],\n\t] satisfies Array<ConfigWithExtends>;\n\n\treturn defineConfig(...baseConfig, ...(customConfig ?? []));\n}\n\n// Opt-in rules for authoring native web components\nexport function getWebComponentConfig(files: Array<string>): ConfigWithExtends {\n\tconst bestPractice = webComponentConfigs['flat/best-practice'];\n\n\treturn {\n\t\t...bestPractice,\n\t\tfiles,\n\t\trules: {\n\t\t\t...bestPractice?.rules,\n\t\t\t'wc/define-tag-after-class-definition': 'error',\n\t\t\t'wc/guard-define-call': 'error',\n\t\t\t'wc/max-elements-per-file': 'error',\n\t\t\t'wc/no-child-traversal-in-connectedcallback': 'off',\n\t\t\t'wc/no-constructor': 'error',\n\t\t\t'wc/no-exports-with-element': 'error',\n\t\t\t'wc/no-method-prefixed-with-on': 'error',\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;AAUA,SAAgB,UACf,cACA,SAIyB;CACzB,MAAM,gBAAgB,SAAS,iBAAiB,CAAC;CA4DjD,OAAO,aAAa,GAAG;EAzDtB,OAAO,QAAQ;EACf,GAAG,SAAS,QAAQ;EACpB,GAAG,SAAS,QAAQ;EACpB;GACC,iBAAiB;IAChB,SAAS;KACR,GAAG,QAAQ;KACX,GAAG,QAAQ;KACX,GAAG;IACJ;IACA,QAAQ,SAAS;IACjB,eAAe,SAAS,iBAAiB,EACxC,gBAAgB,KACjB;GACD;GACA,SAAS,EACR,sBAAsB,SAAS,OAChC;GACA,OAAO;IACN,iCAAiC,CAAC,QAAQ,EAAE,SAAS,UAAU,CAAC;IAChE,8CAA8C,CAC7C,SACA;KAAE,UAAU;KAAyB,QAAQ;IAAe,CAC7D;IACA,4CAA4C;IAC5C,qCAAqC,CACpC,SACA;KACC,mBAAmB;KACnB,2BAA2B;KAC3B,gCAAgC;KAChC,oBAAoB;KACpB,mBAAmB;IACpB,CACD;IACA,gDAAgD;IAChD,wBAAwB,CACvB,SACA;KACC,SAAS;KACT,UAAU;IACX,CACD;GACD;EACD;EACA,cAAc,QAAQ;EACtB,EACC,OAAO;GACN,yBAAyB;GACzB,uCAAuC;GACvC,+BAA+B,CAAC,SAAS,EAAE,kBAAkB,YAAY,CAAC;GAC1E,iCAAiC;EAClC,EACD;EACA,cAAc,QAAQ;CAGS,GAAG,GAAI,gBAAgB,CAAC,CAAE;AAC3D;AAGA,SAAgB,sBAAsB,OAAyC;CAC9E,MAAM,eAAeA,QAAoB;CAEzC,OAAO;EACN,GAAG;EACH;EACA,OAAO;GACN,GAAG,cAAc;GACjB,wCAAwC;GACxC,wBAAwB;GACxB,4BAA4B;GAC5B,8CAA8C;GAC9C,qBAAqB;GACrB,8BAA8B;GAC9B,iCAAiC;EAClC;CACD;AACD"}
1
+ {"version":3,"file":"index.mjs","names":["webComponentConfigs"],"sources":["../src/index.ts"],"sourcesContent":["import type { Config, ConfigWithExtends, ConfigWithExtendsArray } from '@eslint/config-helpers';\n\nimport { defineConfig } from '@eslint/config-helpers';\nimport eslint from '@eslint/js';\nimport astroPlugin from 'eslint-plugin-astro';\nimport perfectionist from 'eslint-plugin-perfectionist';\nimport unicornPlugin from 'eslint-plugin-unicorn';\nimport { configs as webComponentConfigs } from 'eslint-plugin-wc';\nimport globals from 'globals';\nimport tseslint from 'typescript-eslint';\n\ntype RestrictedSyntaxOption = string | { message?: string; selector: string };\n\n// Extend via `getConfig(_, { restrictedSyntax })`\n// Redefining the rule clobbers these, as ESLint replaces rule keys wholesale\nexport const restrictedSyntaxDefaults: Array<RestrictedSyntaxOption> = [\n\t{\n\t\tmessage: 'Separate type imports into their own `import type` statement.',\n\t\tselector: 'ImportDeclaration[importKind=\"value\"] ImportSpecifier[importKind=\"type\"]',\n\t},\n\t{\n\t\tmessage:\n\t\t\t'Use a ternary returning undefined (condition ? <Element /> : undefined) instead of && for conditional rendering.',\n\t\tselector:\n\t\t\t':matches(JSXElement, JSXFragment) > JSXExpressionContainer > LogicalExpression[operator=\"&&\"]',\n\t},\n];\n\n// Astro plugin rules plus the `.astro` parser wiring and disableTypeChecked blocks it needs\n// Types can't resolve through the Astro parser so `astro check` owns type checking\n// For a11y, install eslint-plugin-jsx-a11y and pass a config (e.g. `astroPlugin.configs['flat/jsx-a11y-strict']`)\nexport function getAstroConfig(options?: {\n\ta11y?: ConfigWithExtendsArray;\n}): ConfigWithExtendsArray {\n\treturn [\n\t\t...astroPlugin.configs['flat/recommended'],\n\t\t...(options?.a11y ?? []),\n\t\t// Split from the disableTypeChecked block below so it doesn't clobber these parserOptions\n\t\t{\n\t\t\tfiles: ['**/*.astro'],\n\t\t\tlanguageOptions: {\n\t\t\t\tparserOptions: {\n\t\t\t\t\textraFileExtensions: ['.astro'],\n\t\t\t\t\tparser: tseslint.parser,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tfiles: ['**/*.astro'],\n\t\t\t...tseslint.configs.disableTypeChecked,\n\t\t},\n\t\t{\n\t\t\tfiles: ['**/*.astro/*.ts', '*.astro/*.ts'],\n\t\t\t...tseslint.configs.disableTypeChecked,\n\t\t},\n\t\t{\n\t\t\tfiles: ['**/*.js', '**/*.mjs', '**/*.cjs'],\n\t\t\t...tseslint.configs.disableTypeChecked,\n\t\t},\n\t];\n}\n\nexport function getConfig(\n\tcustomConfig?: ConfigWithExtendsArray,\n\toptions?: {\n\t\tcustomGlobals?: Record<string, 'readonly' | 'writeable'>;\n\t\tparserOptions?: NonNullable<Config['languageOptions']>['parserOptions'];\n\t\trestrictedSyntax?: Array<RestrictedSyntaxOption>;\n\t},\n): ConfigWithExtendsArray {\n\tconst customGlobals = options?.customGlobals ?? {};\n\tconst restrictedSyntax = [...restrictedSyntaxDefaults, ...(options?.restrictedSyntax ?? [])];\n\n\tconst baseConfig = [\n\t\teslint.configs.recommended,\n\t\t...tseslint.configs.strictTypeChecked,\n\t\t...tseslint.configs.stylisticTypeChecked,\n\t\t{\n\t\t\tlanguageOptions: {\n\t\t\t\tglobals: {\n\t\t\t\t\t...globals.builtin,\n\t\t\t\t\t...globals.nodeBuiltin,\n\t\t\t\t\t...customGlobals,\n\t\t\t\t},\n\t\t\t\tparser: tseslint.parser,\n\t\t\t\tparserOptions: options?.parserOptions ?? {\n\t\t\t\t\tprojectService: true,\n\t\t\t\t},\n\t\t\t},\n\t\t\tplugins: {\n\t\t\t\t'@typescript-eslint': tseslint.plugin,\n\t\t\t},\n\t\t\trules: {\n\t\t\t\t'@typescript-eslint/array-type': ['warn', { default: 'generic' }],\n\t\t\t\t'@typescript-eslint/consistent-type-imports': [\n\t\t\t\t\t'error',\n\t\t\t\t\t{ fixStyle: 'separate-type-imports', prefer: 'type-imports' },\n\t\t\t\t],\n\t\t\t\t'@typescript-eslint/no-non-null-assertion': 'off',\n\t\t\t\t'@typescript-eslint/no-unused-vars': [\n\t\t\t\t\t'error',\n\t\t\t\t\t{\n\t\t\t\t\t\targsIgnorePattern: '^_',\n\t\t\t\t\t\tcaughtErrorsIgnorePattern: '^_',\n\t\t\t\t\t\tdestructuredArrayIgnorePattern: '^_',\n\t\t\t\t\t\tignoreRestSiblings: true,\n\t\t\t\t\t\tvarsIgnorePattern: '^_',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\t'@typescript-eslint/prefer-nullish-coalescing': 'off',\n\t\t\t\t'no-restricted-syntax': ['error', ...restrictedSyntax],\n\t\t\t},\n\t\t},\n\t\tunicornPlugin.configs.recommended,\n\t\t{\n\t\t\trules: {\n\t\t\t\t'unicorn/filename-case': 'warn',\n\t\t\t\t'unicorn/no-array-callback-reference': 'off', // I prefer this pattern for filtering/sorting content\n\t\t\t\t'unicorn/number-literal-case': ['error', { hexadecimalValue: 'lowercase' }], // Lowercase hex to match Prettier\n\t\t\t\t'unicorn/prevent-abbreviations': 'off', // I *like* abbreviations!\n\t\t\t},\n\t\t},\n\t\tperfectionist.configs['recommended-natural'],\n\t] satisfies Array<ConfigWithExtends>;\n\n\treturn defineConfig(...baseConfig, ...(customConfig ?? []));\n}\n\n// Opt-in rules for authoring native web components\nexport function getWebComponentConfig(files: Array<string>): ConfigWithExtends {\n\tconst bestPractice = webComponentConfigs['flat/best-practice'];\n\n\treturn {\n\t\t...bestPractice,\n\t\tfiles,\n\t\trules: {\n\t\t\t...bestPractice?.rules,\n\t\t\t'wc/define-tag-after-class-definition': 'error',\n\t\t\t'wc/guard-define-call': 'error',\n\t\t\t'wc/max-elements-per-file': 'error',\n\t\t\t'wc/no-child-traversal-in-connectedcallback': 'off',\n\t\t\t'wc/no-constructor': 'error',\n\t\t\t'wc/no-exports-with-element': 'error',\n\t\t\t'wc/no-method-prefixed-with-on': 'error',\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;AAeA,MAAa,2BAA0D,CACtE;CACC,SAAS;CACT,UAAU;AACX,GACA;CACC,SACC;CACD,UACC;AACF,CACD;AAKA,SAAgB,eAAe,SAEJ;CAC1B,OAAO;EACN,GAAG,YAAY,QA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iCAAiC;EAClC,EACD;EACA,cAAc,QAAQ;CAGS,GAAG,GAAI,gBAAgB,CAAC,CAAE;AAC3D;AAGA,SAAgB,sBAAsB,OAAyC;CAC9E,MAAM,eAAeA,QAAoB;CAEzC,OAAO;EACN,GAAG;EACH;EACA,OAAO;GACN,GAAG,cAAc;GACjB,wCAAwC;GACxC,wBAAwB;GACxB,4BAA4B;GAC5B,8CAA8C;GAC9C,qBAAqB;GACrB,8BAA8B;GAC9B,iCAAiC;EAClC;CACD;AACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xsynaptic/eslint-config",
3
- "version": "3.5.0",
3
+ "version": "3.6.0",
4
4
  "description": "An ESLint config factory for TypeScript projects",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -34,6 +34,7 @@
34
34
  "dependencies": {
35
35
  "@eslint/config-helpers": "^0.6.0",
36
36
  "@eslint/js": "^9.39.4",
37
+ "eslint-plugin-astro": "^1.7.0",
37
38
  "eslint-plugin-perfectionist": "^5.9.0",
38
39
  "eslint-plugin-unicorn": "^64.0.0",
39
40
  "eslint-plugin-wc": "^3.1.0",