@2digits/eslint-plugin 3.3.0 → 3.4.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 +6 -9
- package/dist/index.mjs +1 -1
- package/package.json +3 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _typescript_eslint_utils_ts_eslint0 from "@typescript-eslint/utils/ts-eslint";
|
|
2
2
|
import { FlatConfig } from "@typescript-eslint/utils/ts-eslint";
|
|
3
|
+
import { Linter } from "eslint";
|
|
3
4
|
|
|
4
|
-
//#region src/utils/index.d.ts
|
|
5
|
-
/** @public */
|
|
6
|
-
interface RuleModule<T extends ReadonlyArray<unknown>> extends Rule.RuleModule {
|
|
7
|
-
defaultOptions: T;
|
|
8
|
-
}
|
|
9
|
-
//#endregion
|
|
10
5
|
//#region src/index.d.ts
|
|
11
6
|
declare const plugin: {
|
|
12
7
|
meta: {
|
|
@@ -14,8 +9,9 @@ declare const plugin: {
|
|
|
14
9
|
version: string;
|
|
15
10
|
};
|
|
16
11
|
rules: {
|
|
17
|
-
'if-curly': RuleModule<[]>;
|
|
18
|
-
'
|
|
12
|
+
'if-curly': _typescript_eslint_utils_ts_eslint0.RuleModule<"missingCurly", [], unknown, _typescript_eslint_utils_ts_eslint0.RuleListener>;
|
|
13
|
+
'prefer-inline-handlers': _typescript_eslint_utils_ts_eslint0.RuleModule<"preferInlineHandler", [], unknown, _typescript_eslint_utils_ts_eslint0.RuleListener>;
|
|
14
|
+
'type-param-names': _typescript_eslint_utils_ts_eslint0.RuleModule<"prefix" | "initial" | "remainder" | "suggestRename", [], unknown, _typescript_eslint_utils_ts_eslint0.RuleListener>;
|
|
19
15
|
};
|
|
20
16
|
configs: {
|
|
21
17
|
recommended: {
|
|
@@ -24,6 +20,7 @@ declare const plugin: {
|
|
|
24
20
|
};
|
|
25
21
|
rules: {
|
|
26
22
|
'@2digits/if-curly': "error";
|
|
23
|
+
'@2digits/prefer-inline-handlers': "error";
|
|
27
24
|
'@2digits/type-param-names': "error";
|
|
28
25
|
};
|
|
29
26
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{AST_NODE_TYPES as e,AST_TOKEN_TYPES as t}from"@typescript-eslint/utils";
|
|
1
|
+
import{AST_NODE_TYPES as e,AST_TOKEN_TYPES as t,ESLintUtils as n}from"@typescript-eslint/utils";var r=`3.4.0`;const i={rules:{"@2digits/if-curly":`error`,"@2digits/prefer-inline-handlers":`error`,"@2digits/type-param-names":`error`}},a=n.RuleCreator(e=>`https://github.com/2digits-agency/configs/tree/main/packages/eslint-plugin/src/rules/${e}.ts`),o=a({name:`if-curly`,meta:{type:`suggestion`,docs:{description:`Require curly braces around if statement bodies`},fixable:`code`,schema:[],messages:{missingCurly:`Expected curly braces around if statement body`}},defaultOptions:[],create(n){let r=n.sourceCode;function i(e){return(r.lines[e.loc.start.line-1]??``).match(/^(\s*)/)?.[1]??``}function a(a,o,s=!1){if(a.type===e.BlockStatement)return;let c=s?r.getTokenBefore(a,e=>e.type===t.Keyword&&e.value===`else`):r.getFirstToken(o);n.report({node:a,loc:c?.loc??a.loc,messageId:`missingCurly`,fix(e){let t=r.getText(a),n=i(a);return e.replaceText(a,`{\n${n} ${t}\n${n}}`)}})}return{IfStatement(t){a(t.consequent,t,!1),t.alternate&&t.alternate.type!==e.IfStatement&&a(t.alternate,t,!0)}}}}),s=new Set([`useCallback`,`useMemo`]),c=new WeakMap;function l(t){let n=c.get(t);if(n!==void 0)return n;let r=t.parent,i;for(;r;){if(r.type===e.FunctionDeclaration||r.type===e.FunctionExpression||r.type===e.ArrowFunctionExpression){i=r;break}r=r.parent}return c.set(t,i),i}function u(t){if(t.type!==e.CallExpression)return!1;let{callee:n}=t;return n.type===e.Identifier?s.has(n.name):!1}function d(e,t){let n=e;for(;n;){let e=n.set.get(t);if(e)return e;n=n.upper}}function f(t,n){if(n.type===e.FunctionDeclaration){let e=n.params.map(e=>t.getText(e)).join(`, `),r=t.getText(n.body);return`${n.async?`async `:``}(${e}) => ${r}`}return t.getText(n)}function p(t){if(t.type===e.FunctionDeclaration)return t;if(t.type===e.VariableDeclarator&&t.parent.declarations.length===1)return t.parent}const m=a({name:`prefer-inline-handlers`,meta:{type:`suggestion`,docs:{description:`Discourage hoisting event handlers only used once in JSX; prefer inlining`},fixable:`code`,schema:[],messages:{preferInlineHandler:`Handler '{{name}}' is only used once as a JSX prop. Inline it where it's used.`}},defaultOptions:[],create(t){let n=t.sourceCode;function r(r,i,a){let o=d(n.getScope(i),r.name);if(!o)return;let s=o.references.filter(e=>e.isRead()&&e.identifier!==r);if(s.length!==1)return;let c=s[0];if(!c)return;let l=c.identifier,{parent:u}=l;u.type===e.JSXExpressionContainer&&u.parent.type===e.JSXAttribute&&t.report({node:r,messageId:`preferInlineHandler`,data:{name:r.name},fix(e){let t=f(n,a),r=p(i),o=[e.replaceText(l,t)];return r&&o.push(e.remove(r)),o}})}return{"VariableDeclarator[init.type=ArrowFunctionExpression], VariableDeclarator[init.type=FunctionExpression]":function(t){if(t.id.type!==e.Identifier||!t.init||!l(t)||u(t.init))return;let n=t.init;r(t.id,t,n)},"VariableDeclarator[init.type=CallExpression]":function(t){t.id.type===e.Identifier&&(!t.init||t.init.type!==e.CallExpression||l(t)&&u(t.init))},FunctionDeclaration(e){e.id&&l(e)&&r(e.id,e,e)}}}}),h=/^[T$][A-Z][a-z]+\d*$/,g=/^[T$]/,_=/^[T$][A-Z]/,v=/^[T$][A-Z][a-z]/,y={prefix:`prefix`,initial:`initial`,remainder:`remainder`,suggestRename:`suggestRename`},b=a({name:`type-param-names`,meta:{type:`suggestion`,docs:{description:`Enforce giving proper names to type parameters when there are two or more`},hasSuggestions:!0,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`,suggestRename:`Rename to {{suggestion}}`}},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=x(n);if(r){let i=S(n);e.report({node:t,messageId:r,data:{name:n},suggest:[{messageId:`suggestRename`,data:{suggestion:i},fix(e){return e.replaceText(t.name,i)}}]})}}}}}});function x(e){if(!h.test(e)){if(!g.test(e))return y.prefix;if(!_.test(e))return y.initial;if(!v.test(e))return y.remainder}}function S(e){if(!g.test(e))return`T${e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()}`;let t=e.charAt(0),n=e.slice(1);return n.length===0?`${t}Value`:`${t}${n.charAt(0).toUpperCase()+(n.length>1?n.slice(1).toLowerCase():`a`)}`}const C={meta:{name:`@2digits`,version:r},rules:{"if-curly":o,"prefer-inline-handlers":m,"type-param-names":b},configs:{recommended:{plugins:{"@2digits":{}},rules:i.rules}}};C.configs.recommended.plugins[`@2digits`]=C;var w=C;export{w as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@2digits/eslint-plugin",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
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",
|
|
@@ -27,15 +27,14 @@
|
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"public": true,
|
|
29
29
|
"dependencies": {
|
|
30
|
+
"@typescript-eslint/scope-manager": "8.50.1",
|
|
30
31
|
"@typescript-eslint/utils": "8.50.1",
|
|
31
|
-
"eslint": "9.39.2"
|
|
32
|
-
"ts-pattern": "5.9.0"
|
|
32
|
+
"eslint": "9.39.2"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@arethetypeswrong/core": "0.18.2",
|
|
36
36
|
"@typescript-eslint/parser": "8.50.1",
|
|
37
37
|
"eslint-vitest-rule-tester": "3.0.1",
|
|
38
|
-
"magic-regexp": "0.10.0",
|
|
39
38
|
"publint": "0.3.16",
|
|
40
39
|
"tsdown": "0.18.3",
|
|
41
40
|
"typescript": "5.9.3",
|