@2digits/eslint-plugin 3.0.10 → 3.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/dist/index.d.mts CHANGED
@@ -1,38 +1,34 @@
1
- import { Rule, Linter } from 'eslint';
2
- import { FlatConfig } from '@typescript-eslint/utils/ts-eslint';
1
+ import { Linter, Rule } from "eslint";
2
+ import { FlatConfig } from "@typescript-eslint/utils/ts-eslint";
3
3
 
4
+ //#region src/utils/index.d.ts
4
5
  /** @public */
5
6
  interface RuleModule<T extends ReadonlyArray<unknown>> extends Rule.RuleModule {
6
- defaultOptions: T;
7
+ defaultOptions: T;
7
8
  }
8
-
9
+ //#endregion
10
+ //#region src/index.d.ts
9
11
  declare const plugin: {
10
- meta: {
11
- name: string;
12
- version: string;
13
- };
14
- rules: {
15
- 'type-param-names': RuleModule<[]>;
16
- };
17
- configs: {
18
- recommended: {
19
- plugins: {
20
- '@2digits': FlatConfig.Plugin;
21
- };
22
- rules: {
23
- '@2digits/type-param-names': "error";
24
- };
25
- };
12
+ meta: {
13
+ name: string;
14
+ version: string;
15
+ };
16
+ rules: {
17
+ 'type-param-names': RuleModule<[]>;
18
+ };
19
+ configs: {
20
+ recommended: {
21
+ plugins: {
22
+ '@2digits': FlatConfig.Plugin;
23
+ };
24
+ rules: {
25
+ '@2digits/type-param-names': "error";
26
+ };
26
27
  };
28
+ };
27
29
  };
28
-
29
30
  type RuleDefinitions = (typeof plugin)['rules'];
30
- type RuleOptions = {
31
- [K in keyof RuleDefinitions]: RuleDefinitions[K]['defaultOptions'];
32
- };
33
- type Rules = {
34
- [K in keyof RuleOptions]: Linter.RuleEntry<RuleOptions[K]>;
35
- };
36
-
37
- export { plugin as default };
38
- export type { RuleOptions, Rules };
31
+ type RuleOptions = { [K in keyof RuleDefinitions]: RuleDefinitions[K]['defaultOptions'] };
32
+ type Rules = { [K in keyof RuleOptions]: Linter.RuleEntry<RuleOptions[K]> };
33
+ //#endregion
34
+ export { RuleOptions, Rules, plugin as default };
package/dist/index.mjs CHANGED
@@ -1,129 +1 @@
1
- import { match, P } from 'ts-pattern';
2
-
3
- const version = "3.0.10";
4
- const repository = {
5
- url: "https://github.com/2digits-agency/configs.git",
6
- directory: "packages/eslint-plugin"
7
- };
8
-
9
- const recommended = {
10
- rules: {
11
- "@2digits/type-param-names": "error"
12
- }
13
- };
14
-
15
- const blobUrl = `${repository.url.replaceAll(".git", "")}/tree/main/${repository.directory}/src/rules`;
16
- function RuleCreator(urlCreator) {
17
- return function createNamedRule({
18
- name,
19
- meta,
20
- ...rule
21
- }) {
22
- return createRule({
23
- meta: {
24
- ...meta,
25
- docs: {
26
- ...meta.docs,
27
- url: urlCreator(name)
28
- }
29
- },
30
- ...rule
31
- });
32
- };
33
- }
34
- function createRule({
35
- create,
36
- defaultOptions,
37
- meta
38
- }) {
39
- return {
40
- create: (context) => {
41
- const optionsWithDefault = context.options.map((options, index) => {
42
- return {
43
- ...defaultOptions[index],
44
- ...options
45
- };
46
- });
47
- return create(context, optionsWithDefault);
48
- },
49
- defaultOptions,
50
- meta
51
- };
52
- }
53
- const createEslintRule = RuleCreator((ruleName) => `${blobUrl}${ruleName}.ts`);
54
-
55
- const PrefixRegex = /^(?:T|\$)/;
56
- const InitialRegex = /^(?:T|\$)[A-Z]/;
57
- const RemainderRegex = /^(?:T|\$)[A-Z](?:[a-zA-Z])+/;
58
- const TypeParamRegex = /^(?:T|\$)[A-Z](?:[a-zA-Z])+\d*$/;
59
- const MessageId = {
60
- prefix: "prefix",
61
- initial: "initial",
62
- remainder: "remainder"};
63
- const RULE_NAME = "type-param-names";
64
- const typeParamNames = createEslintRule({
65
- name: RULE_NAME,
66
- meta: {
67
- type: "suggestion",
68
- docs: {
69
- description: "Enforce giving proper names to type parameters when there are two or more"
70
- },
71
- schema: [],
72
- messages: {
73
- prefix: 'Type parameter {{name}} should have a prefix of "T" or "$"',
74
- initial: "Type parameter {{name}}'s name should start with an uppercase letter",
75
- remainder: "Type parameter {{name}}'s name should contain at least one lowercase letter",
76
- regex: "Type parameter {{name}} should match the regex {{regex}}"
77
- }
78
- },
79
- defaultOptions: [],
80
- create(context) {
81
- return {
82
- TSTypeParameterDeclaration(node) {
83
- const { params } = node;
84
- if (params.length === 1 && params.at(0)?.name.name === "T") {
85
- return;
86
- }
87
- for (const param of params) {
88
- const { name } = param.name;
89
- const messageId = getMessageId(name);
90
- if (messageId) {
91
- context.report({
92
- node: param,
93
- messageId,
94
- data: { name }
95
- });
96
- }
97
- }
98
- }
99
- };
100
- }
101
- });
102
- const typeParamSelect = P.string.regex(TypeParamRegex);
103
- const prefixSelect = P.not(P.string.regex(PrefixRegex));
104
- const initialSelect = P.not(P.string.regex(InitialRegex));
105
- const remainderSelect = P.not(P.string.regex(RemainderRegex));
106
- function getMessageId(name) {
107
- return match(name).with(typeParamSelect, () => false).with(prefixSelect, () => MessageId.prefix).with(initialSelect, () => MessageId.initial).with(remainderSelect, () => MessageId.remainder).otherwise(() => false);
108
- }
109
-
110
- const rules = {
111
- "type-param-names": typeParamNames
112
- };
113
-
114
- const plugin = {
115
- meta: {
116
- name: "@2digits",
117
- version
118
- },
119
- rules,
120
- configs: {
121
- recommended: {
122
- plugins: { "@2digits": {} },
123
- rules: recommended.rules
124
- }
125
- }
126
- };
127
- plugin.configs.recommended.plugins["@2digits"] = plugin;
128
-
129
- export { plugin as default };
1
+ import{P as e,match as t}from"ts-pattern";var n=`3.1.1`,r={type:`git`,url:`https://github.com/2digits-agency/configs.git`,directory:`packages/eslint-plugin`};const i={rules:{"@2digits/type-param-names":`error`}},a=/^(?:\(.*\)|\\?.)$/;function o(e){let t=e.toString();return a.test(t)?t:`(?:${t})`}const s=/^(?:\(\?:(.+)\)|(.+))$/,c=/^(?:\(\?:(.+)\)([?+*]|\{[\d,]+\})?|(.+))$/;function l(e){let t=t=>l(`(?<${t}>${`${e}`.replace(s,`$1$2`)})`);return{toString:()=>e.toString(),and:Object.assign((...t)=>l(`${e}${D(...t)}`),{referenceTo:t=>l(`${e}\\k<${t}>`)}),or:(...t)=>l(`(?:${e}|${t.map(e=>D(e)).join(`|`)})`),after:(...t)=>l(`(?<=${D(...t)})${e}`),before:(...t)=>l(`${e}(?=${D(...t)})`),notAfter:(...t)=>l(`(?<!${D(...t)})${e}`),notBefore:(...t)=>l(`${e}(?!${D(...t)})`),times:Object.assign(t=>l(`${o(e)}{${t}}`),{any:()=>l(`${o(e)}*`),atLeast:t=>l(`${o(e)}{${t},}`),atMost:t=>l(`${o(e)}{0,${t}}`),between:(t,n)=>l(`${o(e)}{${t},${n}}`)}),optionally:()=>l(`${o(e)}?`),as:t,groupedAs:t,grouped:()=>l(`${e}`.replace(c,`($1$3)$2`)),at:{lineStart:()=>l(`^${e}`),lineEnd:()=>l(`${e}$`)}}}const u=/[.*+?^${}()|[\]\\/]/g;function d(e){let t=l(`[${e}]`),n=(t,n)=>d(`${e}${f(t)}-${f(n)}`),r=Object.assign(t=>d(`${e}${f(t)}`),{from:n});return Object.assign(t,{orChar:r,from:n})}function f(e){return e.replace(/[-\\^\]]/g,`\\$&`)}const p=Object.assign(e=>d(f(e)),d(``)),m=Object.assign(e=>d(`^${f(e)}`),d(`^`));function h(...e){return l(`(?:${e.map(e=>D(e)).join(`|`)})`)}const g=l(`.`),_=l(`\\b\\w+\\b`),v=l(`\\w`),y=l(`\\b`),b=l(`\\d`),x=l(`\\s`),S=Object.assign(l(`[a-zA-Z]`),{lowercase:l(`[a-z]`),uppercase:l(`[A-Z]`)}),C=l(`\\t`),w=l(`\\n`),T=l(`\\r`),E={word:l(`\\W+`),wordChar:l(`\\W`),wordBoundary:l(`\\B`),digit:l(`\\D`),whitespace:l(`\\S`),letter:Object.assign(l(`[^a-zA-Z]`),{lowercase:l(`[^a-z]`),uppercase:l(`[^A-Z]`)}),tab:l(`[^\\t]`),linefeed:l(`[^\\n]`),carriageReturn:l(`[^\\r]`)};function D(...e){return l(e.map(e=>typeof e==`string`?e.replace(u,`\\$&`):e).join(``))}function O(...e){return l(`${o(D(...e))}+`)}const k=(...e)=>{let t=e.length>1&&(Array.isArray(e[e.length-1])||e[e.length-1]instanceof Set)?e.pop():void 0;return new RegExp(D(...e).toString(),[...t||``].join(``))},A=`${r.url.replaceAll(`.git`,``)}/tree/main/${r.directory}/src/rules`;function j(e){return function({name:t,meta:n,...r}){return M({meta:{...n,docs:{...n.docs,url:e(t)}},...r})}}function M({create:e,defaultOptions:t,meta:n}){return{create:n=>{let r=n.options.map((e,n)=>({...t[n],...e}));return e(n,r)},defaultOptions:t,meta:n}}const N=j(e=>`${A}${e}.ts`),P=k(h(`T`,`$`).at.lineStart()),F=k(h(`T`,`$`).at.lineStart(),S.uppercase),I=k(h(`T`,`$`).at.lineStart(),S.uppercase,O(S)),L=k(h(`T`,`$`).at.lineStart(),S.uppercase,O(S),b.times.any().at.lineEnd()),R={prefix:`prefix`,initial:`initial`,remainder:`remainder`,regex:`regex`},z=`type-param-names`,B=N({name:z,meta:{type:`suggestion`,docs:{description:`Enforce giving proper names to type parameters when there are two or more`},schema:[],messages:{prefix:`Type parameter {{name}} should have a prefix of "T" or "$"`,initial:`Type parameter {{name}}'s name should start with an uppercase letter`,remainder:`Type parameter {{name}}'s name should contain at least one lowercase letter`,regex:`Type parameter {{name}} should match the regex {{regex}}`}},defaultOptions:[],create(e){return{TSTypeParameterDeclaration(t){let{params:n}=t;if(!(n.length===1&&n.at(0)?.name.name===`T`))for(let t of n){let{name:n}=t.name,r=G(n);r&&e.report({node:t,messageId:r,data:{name:n}})}}}}}),V=e.string.regex(L),H=e.not(e.string.regex(P)),U=e.not(e.string.regex(F)),W=e.not(e.string.regex(I));function G(e){return t(e).with(V,()=>!1).with(H,()=>R.prefix).with(U,()=>R.initial).with(W,()=>R.remainder).otherwise(()=>!1)}const K={"type-param-names":B},q={meta:{name:`@2digits`,version:n},rules:K,configs:{recommended:{plugins:{"@2digits":{}},rules:i.rules}}};q.configs.recommended.plugins[`@2digits`]=q;var J=q;export{J as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@2digits/eslint-plugin",
3
- "version": "3.0.10",
3
+ "version": "3.1.1",
4
4
  "description": "An eslint plugin that provides a set of rules to enforce best practices for 2digits projects",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,16 +9,14 @@
9
9
  },
10
10
  "type": "module",
11
11
  "main": "./dist/index.mjs",
12
+ "module": "./dist/index.mjs",
12
13
  "types": "./dist/index.d.mts",
13
14
  "files": [
14
15
  "dist"
15
16
  ],
16
17
  "exports": {
17
- "./package.json": "./package.json",
18
- ".": {
19
- "types": "./dist/index.d.mts",
20
- "default": "./dist/index.mjs"
21
- }
18
+ ".": "./dist/index.mjs",
19
+ "./package.json": "./package.json"
22
20
  },
23
21
  "sideEffects": false,
24
22
  "keywords": [
@@ -29,22 +27,22 @@
29
27
  "license": "MIT",
30
28
  "public": true,
31
29
  "dependencies": {
32
- "@typescript-eslint/utils": "8.33.0",
33
- "eslint": "9.27.0",
30
+ "@typescript-eslint/utils": "8.33.1",
31
+ "eslint": "9.28.0",
34
32
  "ts-pattern": "5.7.1"
35
33
  },
36
34
  "devDependencies": {
37
- "@typescript-eslint/parser": "8.33.0",
35
+ "@typescript-eslint/parser": "8.33.1",
38
36
  "eslint-vitest-rule-tester": "2.2.0",
39
37
  "magic-regexp": "0.10.0",
38
+ "tsdown": "0.12.6",
40
39
  "typescript": "5.8.3",
41
- "unbuild": "3.5.0",
42
- "vitest": "3.1.4",
40
+ "vitest": "3.2.0",
43
41
  "@2digits/tsconfig": "0.7.1"
44
42
  },
45
43
  "scripts": {
46
- "build": "unbuild",
47
- "dev": "unbuild --watch",
44
+ "build": "tsdown --minify",
45
+ "dev": "tsdown --watch",
48
46
  "types": "tsc --noEmit",
49
47
  "test": "vitest --run"
50
48
  }
package/dist/index.d.ts DELETED
@@ -1,38 +0,0 @@
1
- import { Rule, Linter } from 'eslint';
2
- import { FlatConfig } from '@typescript-eslint/utils/ts-eslint';
3
-
4
- /** @public */
5
- interface RuleModule<T extends ReadonlyArray<unknown>> extends Rule.RuleModule {
6
- defaultOptions: T;
7
- }
8
-
9
- declare const plugin: {
10
- meta: {
11
- name: string;
12
- version: string;
13
- };
14
- rules: {
15
- 'type-param-names': RuleModule<[]>;
16
- };
17
- configs: {
18
- recommended: {
19
- plugins: {
20
- '@2digits': FlatConfig.Plugin;
21
- };
22
- rules: {
23
- '@2digits/type-param-names': "error";
24
- };
25
- };
26
- };
27
- };
28
-
29
- type RuleDefinitions = (typeof plugin)['rules'];
30
- type RuleOptions = {
31
- [K in keyof RuleDefinitions]: RuleDefinitions[K]['defaultOptions'];
32
- };
33
- type Rules = {
34
- [K in keyof RuleOptions]: Linter.RuleEntry<RuleOptions[K]>;
35
- };
36
-
37
- export { plugin as default };
38
- export type { RuleOptions, Rules };