@perfective/eslint-config 0.33.0 → 0.34.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.adoc CHANGED
@@ -78,7 +78,7 @@ import { perfectiveEslintConfig } from '@perfective/eslint-config';
78
78
 
79
79
  // Optional dependencies.
80
80
  import { cypressConfig } from '@perfective/eslint-config/cypress';
81
- import { jestConfig } from '@perfective/eslint-config/jest';
81
+ import { jestConfig, jestTypescriptConfig } from '@perfective/eslint-config/jest';
82
82
  import { jestDomConfig } from '@perfective/eslint-config/jest-dom';
83
83
  import { rxjsConfig } from '@perfective/eslint-config/rxjs';
84
84
  import { testingLibraryConfig } from '@perfective/eslint-config/testing-library';
@@ -86,6 +86,7 @@ import { testingLibraryConfig } from '@perfective/eslint-config/testing-library'
86
86
  const eslintConfig = perfectiveEslintConfig([
87
87
  cypressConfig,
88
88
  jestConfig,
89
+ jestTypescriptConfig,
89
90
  jestDomConfig,
90
91
  rxjsConfig,
91
92
  testingLibraryConfig,
@@ -188,6 +189,12 @@ a nominal type for glob patterns.
188
189
  ** `jestFiles: Glob[]`
189
190
  — the link:https://jestjs.io/docs/configuration#testmatch-arraystring[default] glob patterns
190
191
  Jest uses to find test files.
192
+ ** `jestJavascriptFiles: Glob[]`
193
+ — the link:https://jestjs.io/docs/configuration#testmatch-arraystring[default] glob patterns
194
+ Jest uses to find JavaScript test files.
195
+ ** `jestTypescriptFiles: Glob[]`
196
+ — the link:https://jestjs.io/docs/configuration#testmatch-arraystring[default] glob patterns
197
+ Jest uses to find TypeScript test files.
191
198
  ** `cypressFiles: Glob`
192
199
  — the link:https://docs.cypress.io/app/references/configuration#e2e[default] glob pattern
193
200
  Cypress uses to load test files.
@@ -231,6 +238,11 @@ Overrides some rules for `perfectiveEslintConfig` for compatibility with Cypress
231
238
 
232
239
  * `jestConfig(files: Glob[] = jestFiles): Linter.Config`
233
240
  — creates a flat config for `eslint-plugin-jest` for a given list of files globs.
241
+ This config excludes the rules that require `@typescript-eslint` plugin.
242
+ +
243
+ * `jestTypescriptConfig(files: Glob[] = jestTypescriptFiles): Linter.Config`
244
+ — creates a flat config for `eslint-plugin-jest` for a given list of TypeScript file globs.
245
+ This config includes only the rules that require `@typescript-eslint` plugin.
234
246
 
235
247
  === `@perfective/eslint-config/jest-dom`
236
248
 
@@ -257,6 +269,9 @@ Allows to splice `internal` scope packages imports between the global and relati
257
269
 
258
270
  === `@perfective/eslint-config/typescript-eslint`
259
271
 
272
+ * `typescriptEslintDependentConfig(plugin: ESLint.Plugin, rules: Linter.RulesRecord, files: Glob[] = typescriptFiles): Linter.Config`
273
+ — a function to create a flat config for a given `plugin` that requires TypeScript ESLint plugin.
274
+ +
260
275
  * `interface TypescriptEslintNamingConvention`
261
276
  — configuration options for the
262
277
  `link:https://typescript-eslint.io/rules/naming-convention/[@typescript-eslint/naming-convention]` rule.
@@ -270,7 +285,7 @@ Allows to splice `internal` scope packages imports between the global and relati
270
285
  — values for the `@typescript-eslint/naming-convention` rule `format` option.
271
286
  ** `type TypescriptEslintNamingConventionUnderscore`
272
287
  — values for the `@typescript-eslint/naming-convention` rule `leadingUnderscore` and `trailingUnderscore` options.
273
- ** `function typescriptEslintNamingConvention(extensions: TypescriptEslintNamingConvention[] = []): TypescriptEslintNamingConvention[]`
288
+ ** `typescriptEslintNamingConvention(extensions: TypescriptEslintNamingConvention[] = []): TypescriptEslintNamingConvention[]`
274
289
  — creates configuration with the given extensions for the `@typescript-eslint/naming-convention` rule.
275
290
 
276
291
  === `@perfective/eslint-config/unicorn`
@@ -280,5 +295,5 @@ Allows to splice `internal` scope packages imports between the global and relati
280
295
  `link:https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prevent-abbreviations.md[unicorn/prevent-abbreviation]` rule.
281
296
  ** `type UnicornPreventAbbreviationReplacements`
282
297
  — nominal type for the `replacements` option of the `unicorn/prevent-abbreviation` rule.
283
- ** `function unicornPreventAbbreviations( replacements: UnicornPreventAbbreviationReplacements = {}, options: Partial<Pick<UnicornPreventAbbreviations, 'checkProperties'>> = {}): UnicornPreventAbbreviations`
298
+ ** `unicornPreventAbbreviations(replacements: UnicornPreventAbbreviationReplacements = {}, options: Partial<Pick<UnicornPreventAbbreviations, 'checkProperties'>> = {}): UnicornPreventAbbreviations`
284
299
  — creates configuration for the `unicorn/prevent-abbreviation` rule with the given replacements and options.
@@ -1 +1,2 @@
1
1
  export { jestConfig } from './jest-config';
2
+ export { jestTypescriptConfig } from './jest-typescript-config';
@@ -1 +1,2 @@
1
- export { jestConfig } from "./jest-config.js";
1
+ export { jestConfig } from "./jest-config.js";
2
+ export { jestTypescriptConfig } from "./jest-typescript-config.js";
@@ -3,6 +3,8 @@ import { Glob } from '../../linter/glob';
3
3
  /**
4
4
  * Creates a flat config for `eslint-plugin-jest` for a given list of files globs.
5
5
  *
6
+ * This config excludes the rules that require `@typescript-eslint` plugin.
7
+ *
6
8
  * @since v0.31.0
7
9
  */
8
10
  export declare function jestConfig(files?: Glob[]): Linter.Config;
@@ -1,7 +1,6 @@
1
1
  import eslintPluginJest from 'eslint-plugin-jest';
2
2
  import { jestFiles } from "../../linter/glob.js";
3
- import { importNoExtraneousDependencies } from "../import/index.js";
4
- import { typescriptEslintJestRules } from "./typescript-eslint-jest-rules.js";
3
+ import { importNoExtraneousDependencies } from "../import/rules/no-extraneous-dependencies.js";
5
4
  export function jestConfig(files = jestFiles) {
6
5
  return {
7
6
  files,
@@ -11,7 +10,7 @@ export function jestConfig(files = jestFiles) {
11
10
  languageOptions: {
12
11
  globals: eslintPluginJest.environments.globals.globals
13
12
  },
14
- rules: Object.assign(Object.assign(Object.assign({}, perfectiveRules()), typescriptEslintJestRules), {
13
+ rules: Object.assign(Object.assign({}, perfectiveRules()), {
15
14
  'jest/consistent-test-it': ['warn', {
16
15
  fn: 'test',
17
16
  withinDescribe: 'it'
@@ -110,14 +109,6 @@ export function jestConfig(files = jestFiles) {
110
109
  }
111
110
  function perfectiveRules() {
112
111
  return {
113
- '@typescript-eslint/ban-ts-comment': ['error', {
114
- 'ts-expect-error': 'allow-with-description',
115
- 'ts-ignore': true,
116
- 'ts-nocheck': true,
117
- 'ts-check': false
118
- }],
119
- '@typescript-eslint/init-declarations': 'off',
120
- '@typescript-eslint/unbound-method': 'off',
121
112
  'import/no-extraneous-dependencies': ['error', importNoExtraneousDependencies({
122
113
  devDependencies: jestFiles
123
114
  })],
@@ -130,6 +121,6 @@ function perfectiveRules() {
130
121
  }],
131
122
  'prefer-arrow/prefer-arrow-functions': 'off',
132
123
  'promise/always-return': 'off',
133
- '@smarttools/rxjs/no-topromise': 'off'
124
+ 'rxjs-x/no-topromise': 'off'
134
125
  };
135
126
  }
@@ -0,0 +1,10 @@
1
+ import { Linter } from 'eslint';
2
+ import { Glob } from '../../linter/glob';
3
+ /**
4
+ * Creates a flat config for `eslint-plugin-jest` for a given list of TypeScript file globs.
5
+ *
6
+ * This config includes only the rules that require `@typescript-eslint` plugin.
7
+ *
8
+ * @since v0.34.0
9
+ */
10
+ export declare function jestTypescriptConfig(files?: Glob[]): Linter.Config;
@@ -0,0 +1,24 @@
1
+ import eslintPluginJest from 'eslint-plugin-jest';
2
+ import { jestTypescriptFiles } from "../../linter/glob.js";
3
+ import { typescriptEslintDependentConfig } from "../typescript-eslint/typescript-eslint-config.js";
4
+ const jestTypescriptRules = {
5
+ 'jest/no-error-equal': 'error',
6
+ 'jest/no-unnecessary-assertion': 'error',
7
+ 'jest/unbound-method': ['error', {
8
+ ignoreStatic: false
9
+ }],
10
+ 'jest/valid-expect-with-promise': 'error'
11
+ };
12
+ const jestTypescriptEslintRulesOverrides = {
13
+ '@typescript-eslint/ban-ts-comment': ['error', {
14
+ 'ts-expect-error': 'allow-with-description',
15
+ 'ts-ignore': true,
16
+ 'ts-nocheck': true,
17
+ 'ts-check': false
18
+ }],
19
+ '@typescript-eslint/init-declarations': 'off',
20
+ '@typescript-eslint/unbound-method': 'off'
21
+ };
22
+ export function jestTypescriptConfig(files = jestTypescriptFiles) {
23
+ return typescriptEslintDependentConfig(eslintPluginJest, Object.assign(Object.assign({}, jestTypescriptRules), jestTypescriptEslintRulesOverrides), files);
24
+ }
@@ -1 +1,2 @@
1
1
  export { TypescriptEslintNamingConvention, typescriptEslintNamingConvention, TypescriptEslintNamingConventionFormat, TypescriptEslintNamingConventionGroupSelector, TypescriptEslintNamingConventionIndividualSelector, TypescriptEslintNamingConventionSelector, TypescriptEslintNamingConventionUnderscore, } from './rules/typescript-eslint-naming-convention';
2
+ export { typescriptEslintDependentConfig } from './typescript-eslint-config';
@@ -1 +1,2 @@
1
- export { typescriptEslintNamingConvention } from "./rules/typescript-eslint-naming-convention.js";
1
+ export { typescriptEslintNamingConvention } from "./rules/typescript-eslint-naming-convention.js";
2
+ export { typescriptEslintDependentConfig } from "./typescript-eslint-config.js";
@@ -1,2 +1,16 @@
1
- import { Linter } from 'eslint';
1
+ import { ESLint, Linter } from 'eslint';
2
+ import { Glob } from '../../linter/glob';
2
3
  export declare function typescriptEslintConfig(): Linter.Config;
4
+ /**
5
+ * A function to create a flat config for a given `plugin` that requires TypeScript ESLint plugin.
6
+ *
7
+ * This function should be used by other plugin configurations to enable rules that require type information
8
+ * or to change the behavior of the `@typescript-eslint` plugin rules.
9
+ *
10
+ * @param plugin - An ESLint plugin with the rules.
11
+ * @param rules - Rules for the plugin or for the `@typescript-eslint` plugin.
12
+ * @param files - An optional list of globs to narrow down the applicable files.
13
+ *
14
+ * @since v0.34.0
15
+ */
16
+ export declare function typescriptEslintDependentConfig(plugin: ESLint.Plugin, rules: Linter.RulesRecord, files?: Glob[]): Linter.Config;
@@ -1,4 +1,4 @@
1
- import { plugin } from 'typescript-eslint';
1
+ import { plugin as typescriptEslintPlugin } from 'typescript-eslint';
2
2
  import { typescriptFiles } from "../../linter/glob.js";
3
3
  import { typescriptLanguageOptions } from "../../linter/language-options.js";
4
4
  import { extensionRules } from "./extension-rules.js";
@@ -8,8 +8,19 @@ export function typescriptEslintConfig() {
8
8
  files: typescriptFiles,
9
9
  languageOptions: typescriptLanguageOptions(),
10
10
  plugins: {
11
- '@typescript-eslint': plugin
11
+ '@typescript-eslint': typescriptEslintPlugin
12
12
  },
13
13
  rules: Object.assign(Object.assign({}, supportedRules), extensionRules)
14
14
  };
15
+ }
16
+ export function typescriptEslintDependentConfig(plugin, rules, files = typescriptFiles) {
17
+ return {
18
+ files,
19
+ languageOptions: typescriptLanguageOptions(),
20
+ plugins: {
21
+ '@typescript-eslint': typescriptEslintPlugin,
22
+ plugin
23
+ },
24
+ rules
25
+ };
15
26
  }
package/linter/glob.d.ts CHANGED
@@ -40,6 +40,22 @@ export declare const typescriptDeclarationFiles: Glob;
40
40
  * @since v0.31.0
41
41
  */
42
42
  export declare const configurationFiles: string[];
43
+ /**
44
+ * The default glob patterns Jest uses to find JavaScript test files.
45
+ *
46
+ * @see https://jestjs.io/docs/configuration#testmatch-arraystring
47
+ *
48
+ * @since v0.34.0
49
+ */
50
+ export declare const jestJavascriptFiles: Glob[];
51
+ /**
52
+ * The default glob patterns Jest uses to find TypeScript test files.
53
+ *
54
+ * @see https://jestjs.io/docs/configuration#testmatch-arraystring
55
+ *
56
+ * @since v0.34.0
57
+ */
58
+ export declare const jestTypescriptFiles: Glob[];
43
59
  /**
44
60
  * The default glob patterns Jest uses to find test files.
45
61
  *
package/linter/glob.js CHANGED
@@ -4,5 +4,7 @@ export const tsxFiles = '**/*.tsx';
4
4
  export const typescriptFiles = ['**/*.{ts,cts,mts}', tsxFiles];
5
5
  export const typescriptDeclarationFiles = '**/*.d.{ts,cts,mts}';
6
6
  export const configurationFiles = ['**/.*.js', '**/*.config.js', '**/gulpfile.js'];
7
- export const jestFiles = ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'];
7
+ export const jestJavascriptFiles = ['**/__tests__/**/*.js?(x)', '**/?(*.)+(spec|test).js?(x)'];
8
+ export const jestTypescriptFiles = ['**/__tests__/**/*.ts?(x)', '**/?(*.)+(spec|test).ts?(x)'];
9
+ export const jestFiles = [...jestJavascriptFiles, ...jestTypescriptFiles];
8
10
  export const cypressFiles = 'cypress/e2e/**/*.cy.{js,jsx,ts,tsx}';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perfective/eslint-config",
3
- "version": "0.33.0",
3
+ "version": "0.34.0",
4
4
  "description": "ESLint shareable rules configuration",
5
5
  "keywords": ["code quality", "code standard", "code style", "eslint", "eslint config", "lint", "perfective", "tslint", "tslint config", "typescript"],
6
6
  "author": "Andrey Mikheychik <a.mikheychik@gmail.com>",
@@ -21,7 +21,7 @@
21
21
  "eslint-plugin-import": "^2.32.0",
22
22
  "eslint-plugin-jest": "^29.12.1",
23
23
  "eslint-plugin-jest-dom": "^5.5.0",
24
- "eslint-plugin-jsdoc": "^61.5.0",
24
+ "eslint-plugin-jsdoc": "^61.7.1",
25
25
  "eslint-plugin-n": "^17.23.1",
26
26
  "eslint-plugin-prefer-arrow": "^1.2.3",
27
27
  "eslint-plugin-promise": "^7.2.1",
@@ -1,2 +0,0 @@
1
- import { Linter } from 'eslint';
2
- export declare const typescriptEslintJestRules: Linter.RulesRecord;
@@ -1,8 +0,0 @@
1
- export const typescriptEslintJestRules = {
2
- 'jest/no-error-equal': 'error',
3
- 'jest/no-unnecessary-assertion': 'error',
4
- 'jest/unbound-method': ['error', {
5
- ignoreStatic: false
6
- }],
7
- 'jest/valid-expect-with-promise': 'error'
8
- };