@sarj/eslint-plugin 16.42.1 → 17.1.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
@@ -8,6 +8,8 @@ Custom ESLint rules for hypermodern TypeScript / React / Next.js projects
8
8
  npm install --save-dev @sarj/eslint-plugin
9
9
  ```
10
10
 
11
+ Version 17 requires ESLint 10.13.0 or later. The plugin, rules and flat presets use ESLint's native TypeScript contracts and compose directly with `defineConfig` from `eslint/config`. Use `Linter.Config` and `ESLint.Options` from `eslint` for consumer annotations; legacy `TSESLint.Plugin` and `TSESLint.FlatConfig.Config` annotations are no longer supported. The exported rule names, preset severities and option settings are unchanged.
12
+
11
13
  Rules and configuration are documented in the generated rule directory.
12
14
 
13
15
  [Documentation](https://code-standards.sarj.ai/rules/eslint/) · [Source](https://github.com/sarj-ai/code-standards)
@@ -1,4 +1,50 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
1
+ import { ESLintUtils, TSESLint, TSESTree, JSONSchema } from '@typescript-eslint/utils';
2
+ import { Linter, JSRuleDefinition } from 'eslint';
3
+ import { RuleDefinition, RuleVisitor } from '@eslint/core';
4
+
5
+ /** @fileoverview _eslint-rule — native TypeScript rule contexts and owned option metadata. */
6
+
7
+ type NativeJavaScriptSource = Parameters<JSRuleDefinition["create"]>[0]["sourceCode"];
8
+ type TypeScriptSourceCode = Pick<TSESLint.SourceCode, Exclude<Extract<keyof TSESLint.SourceCode, keyof NativeJavaScriptSource>, "visitorKeys">> & Pick<NativeJavaScriptSource, "visitorKeys"> & Pick<NativeJavaScriptSource, Exclude<keyof NativeJavaScriptSource, keyof TSESLint.SourceCode>>;
9
+ type NativeRuleListener = {
10
+ [Selector in keyof TSESLint.RuleListener as string extends Selector ? never : number extends Selector ? never : Selector]: TSESLint.RuleListener[Selector];
11
+ } & RuleVisitor;
12
+ type Definition<Options extends readonly unknown[], MessageIds extends string> = RuleDefinition<{
13
+ LangOptions: Linter.LanguageOptions;
14
+ ExtRuleDocs: Record<string, unknown>;
15
+ RuleOptions: [...Options];
16
+ MessageIds: MessageIds;
17
+ Code: TypeScriptSourceCode;
18
+ Node: TSESTree.Node | TSESTree.Token;
19
+ Visitor: NativeRuleListener;
20
+ }>;
21
+ type EngineRuleContext<MessageIds extends string, Options extends readonly unknown[]> = Parameters<Definition<Options, MessageIds>["create"]>[0];
22
+ type NativeRuleContext<MessageIds extends string, Options extends readonly unknown[]> = Omit<EngineRuleContext<MessageIds, Options>, "options"> & {
23
+ readonly options: Readonly<Partial<Options>>;
24
+ };
25
+ type NativeRuleConfiguration<Options extends readonly unknown[], MessageIds extends string> = Omit<ESLintUtils.RuleWithMetaAndName<Options, MessageIds>, "create"> & {
26
+ create(this: void, context: NativeRuleContext<MessageIds, Options>, options: Readonly<Options>): NativeRuleListener;
27
+ } & (readonly [] extends Options ? unknown : {
28
+ readonly defaultOptions: Readonly<Options>;
29
+ } | {
30
+ readonly meta: {
31
+ readonly defaultOptions: Readonly<Options>;
32
+ };
33
+ });
34
+ type OwnedMetadata<Options extends readonly unknown[], MessageIds extends string> = Omit<ESLintUtils.RuleWithMetaAndName<Options, MessageIds>["meta"], "schema" | "defaultOptions" | "docs"> & {
35
+ docs: ESLintUtils.RuleWithMetaAndName<Options, MessageIds>["meta"]["docs"] & {
36
+ url: string;
37
+ };
38
+ schema: JSONSchema.JSONSchema4 | JSONSchema.JSONSchema4[];
39
+ defaultOptions?: [...Options];
40
+ };
41
+ interface NativeRule<Options extends readonly unknown[], MessageIds extends string> {
42
+ name: string;
43
+ defaultOptions: Readonly<Options> | undefined;
44
+ meta: OwnedMetadata<Options, MessageIds>;
45
+ create(context: EngineRuleContext<MessageIds, Options>): NativeRuleListener;
46
+ }
47
+ declare function createNativeRule<Options extends readonly unknown[], MessageIds extends string>(config: NativeRuleConfiguration<Options, MessageIds>, url: (name: string) => string): NativeRule<Options, MessageIds>;
2
48
 
3
49
  /**
4
50
  * @fileoverview _docs — typed source-owned rule documentation and executable examples.
@@ -98,10 +144,7 @@ interface PublicRuleSpec {
98
144
  readonly optionsSchema: object | null;
99
145
  readonly examples: readonly PublicRuleExample[];
100
146
  }
101
- declare const eslintCreateRule: <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<Options, MessageIds, unknown>>) => ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener> & {
102
- name: string;
103
- };
104
- type DocumentedRule<Options extends readonly unknown[], MessageIds extends string> = ReturnType<typeof eslintCreateRule<Options, MessageIds>> & {
147
+ type DocumentedRule<Options extends readonly unknown[], MessageIds extends string> = ReturnType<typeof createNativeRule<Options, MessageIds>> & {
105
148
  /** Non-enumerable so the public ESLint rule shape remains unchanged. */
106
149
  readonly documentation?: NativeRuleSpec;
107
150
  };
@@ -1,4 +1,50 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
1
+ import { ESLintUtils, TSESLint, TSESTree, JSONSchema } from '@typescript-eslint/utils';
2
+ import { Linter, JSRuleDefinition } from 'eslint';
3
+ import { RuleDefinition, RuleVisitor } from '@eslint/core';
4
+
5
+ /** @fileoverview _eslint-rule — native TypeScript rule contexts and owned option metadata. */
6
+
7
+ type NativeJavaScriptSource = Parameters<JSRuleDefinition["create"]>[0]["sourceCode"];
8
+ type TypeScriptSourceCode = Pick<TSESLint.SourceCode, Exclude<Extract<keyof TSESLint.SourceCode, keyof NativeJavaScriptSource>, "visitorKeys">> & Pick<NativeJavaScriptSource, "visitorKeys"> & Pick<NativeJavaScriptSource, Exclude<keyof NativeJavaScriptSource, keyof TSESLint.SourceCode>>;
9
+ type NativeRuleListener = {
10
+ [Selector in keyof TSESLint.RuleListener as string extends Selector ? never : number extends Selector ? never : Selector]: TSESLint.RuleListener[Selector];
11
+ } & RuleVisitor;
12
+ type Definition<Options extends readonly unknown[], MessageIds extends string> = RuleDefinition<{
13
+ LangOptions: Linter.LanguageOptions;
14
+ ExtRuleDocs: Record<string, unknown>;
15
+ RuleOptions: [...Options];
16
+ MessageIds: MessageIds;
17
+ Code: TypeScriptSourceCode;
18
+ Node: TSESTree.Node | TSESTree.Token;
19
+ Visitor: NativeRuleListener;
20
+ }>;
21
+ type EngineRuleContext<MessageIds extends string, Options extends readonly unknown[]> = Parameters<Definition<Options, MessageIds>["create"]>[0];
22
+ type NativeRuleContext<MessageIds extends string, Options extends readonly unknown[]> = Omit<EngineRuleContext<MessageIds, Options>, "options"> & {
23
+ readonly options: Readonly<Partial<Options>>;
24
+ };
25
+ type NativeRuleConfiguration<Options extends readonly unknown[], MessageIds extends string> = Omit<ESLintUtils.RuleWithMetaAndName<Options, MessageIds>, "create"> & {
26
+ create(this: void, context: NativeRuleContext<MessageIds, Options>, options: Readonly<Options>): NativeRuleListener;
27
+ } & (readonly [] extends Options ? unknown : {
28
+ readonly defaultOptions: Readonly<Options>;
29
+ } | {
30
+ readonly meta: {
31
+ readonly defaultOptions: Readonly<Options>;
32
+ };
33
+ });
34
+ type OwnedMetadata<Options extends readonly unknown[], MessageIds extends string> = Omit<ESLintUtils.RuleWithMetaAndName<Options, MessageIds>["meta"], "schema" | "defaultOptions" | "docs"> & {
35
+ docs: ESLintUtils.RuleWithMetaAndName<Options, MessageIds>["meta"]["docs"] & {
36
+ url: string;
37
+ };
38
+ schema: JSONSchema.JSONSchema4 | JSONSchema.JSONSchema4[];
39
+ defaultOptions?: [...Options];
40
+ };
41
+ interface NativeRule<Options extends readonly unknown[], MessageIds extends string> {
42
+ name: string;
43
+ defaultOptions: Readonly<Options> | undefined;
44
+ meta: OwnedMetadata<Options, MessageIds>;
45
+ create(context: EngineRuleContext<MessageIds, Options>): NativeRuleListener;
46
+ }
47
+ declare function createNativeRule<Options extends readonly unknown[], MessageIds extends string>(config: NativeRuleConfiguration<Options, MessageIds>, url: (name: string) => string): NativeRule<Options, MessageIds>;
2
48
 
3
49
  /**
4
50
  * @fileoverview _docs — typed source-owned rule documentation and executable examples.
@@ -98,10 +144,7 @@ interface PublicRuleSpec {
98
144
  readonly optionsSchema: object | null;
99
145
  readonly examples: readonly PublicRuleExample[];
100
146
  }
101
- declare const eslintCreateRule: <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<Options, MessageIds, unknown>>) => ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener> & {
102
- name: string;
103
- };
104
- type DocumentedRule<Options extends readonly unknown[], MessageIds extends string> = ReturnType<typeof eslintCreateRule<Options, MessageIds>> & {
147
+ type DocumentedRule<Options extends readonly unknown[], MessageIds extends string> = ReturnType<typeof createNativeRule<Options, MessageIds>> & {
105
148
  /** Non-enumerable so the public ESLint rule shape remains unchanged. */
106
149
  readonly documentation?: NativeRuleSpec;
107
150
  };