eslint-plugin-conventions 4.2.6 → 4.2.7
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/package.json +2 -2
- package/src/index.js +1 -45
- package/src/lib/eslint-plugin-conventions.js +1 -6
- package/src/oxlint.js +1 -3
- package/src/rules/conventions/analytics-event-naming.js +1 -93
- package/src/rules/conventions/consistent-existence-index-check.js +1 -130
- package/src/rules/conventions/expiring-todo-comments.js +1 -283
- package/src/rules/conventions/filename-case.js +1 -234
- package/src/rules/conventions/no-commented-code.js +1 -237
- package/src/rules/conventions/no-console-spaces.js +1 -113
- package/src/rules/conventions/no-json-schema-tags.js +1 -159
- package/src/rules/conventions/no-magic-numbers.js +2 -185
- package/src/rules/conventions/no-raw-cross-property-href.js +1 -76
- package/src/rules/conventions/prefer-code-point.js +1 -80
- package/src/rules/conventions/prefer-dependency-version-strategy.js +1 -201
- package/src/rules/conventions/prefer-dom-node-text-content.js +1 -127
- package/src/rules/conventions/require-data-testid.js +1 -179
- package/src/rules/conventions/utm-taxonomy.js +1 -106
- package/src/rules/deprecation/no-deprecated-api.js +1 -161
|
@@ -1,161 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noDeprecatedApi = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
-
exports.noDeprecatedApi = (0, eslint_devkit_2.createRule)({
|
|
7
|
-
name: 'no-deprecated-api',
|
|
8
|
-
meta: {
|
|
9
|
-
type: 'problem',
|
|
10
|
-
docs: {
|
|
11
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-conventions/docs/rules/no-deprecated-api.md',
|
|
12
|
-
description: 'Prevent usage of deprecated APIs with migration context',
|
|
13
|
-
cwe: 'CWE-1078',
|
|
14
|
-
cvss: 7.5,
|
|
15
|
-
},
|
|
16
|
-
fixable: 'code',
|
|
17
|
-
hasSuggestions: true,
|
|
18
|
-
messages: {
|
|
19
|
-
deprecatedAPI: (0, eslint_devkit_1.formatLLMMessage)({
|
|
20
|
-
icon: eslint_devkit_1.MessageIcons.DEPRECATION,
|
|
21
|
-
issueName: 'Deprecated API',
|
|
22
|
-
cwe: 'CWE-1078',
|
|
23
|
-
description: 'Deprecated API detected',
|
|
24
|
-
severity: 'HIGH',
|
|
25
|
-
fix: 'Migrate to recommended alternative with timeline guidance',
|
|
26
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference',
|
|
27
|
-
}),
|
|
28
|
-
useReplacement: (0, eslint_devkit_1.formatLLMMessage)({
|
|
29
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
30
|
-
issueName: 'Use Replacement',
|
|
31
|
-
description: 'Replace with recommended API',
|
|
32
|
-
severity: 'LOW',
|
|
33
|
-
fix: 'Replace with {{replacement}}',
|
|
34
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference',
|
|
35
|
-
}),
|
|
36
|
-
},
|
|
37
|
-
schema: [
|
|
38
|
-
{
|
|
39
|
-
type: 'object',
|
|
40
|
-
properties: {
|
|
41
|
-
apis: {
|
|
42
|
-
type: 'array',
|
|
43
|
-
items: {
|
|
44
|
-
type: 'object',
|
|
45
|
-
properties: {
|
|
46
|
-
name: { type: 'string' },
|
|
47
|
-
replacement: { type: 'string' },
|
|
48
|
-
deprecatedSince: { type: 'string' },
|
|
49
|
-
removalDate: { type: 'string' },
|
|
50
|
-
reason: { type: 'string' },
|
|
51
|
-
migrationGuide: { type: 'string' },
|
|
52
|
-
},
|
|
53
|
-
required: ['name', 'replacement', 'deprecatedSince', 'reason'],
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
warnDaysBeforeRemoval: {
|
|
57
|
-
type: 'number',
|
|
58
|
-
default: 90,
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
additionalProperties: false,
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
},
|
|
65
|
-
defaultOptions: [
|
|
66
|
-
{
|
|
67
|
-
apis: [],
|
|
68
|
-
warnDaysBeforeRemoval: 90,
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
create(context) {
|
|
72
|
-
const options = context.options[0] || {};
|
|
73
|
-
const { apis = [], warnDaysBeforeRemoval = 90 } = options;
|
|
74
|
-
if (!apis || apis.length === 0) {
|
|
75
|
-
return {};
|
|
76
|
-
}
|
|
77
|
-
const calculateDaysRemaining = (removalDate) => {
|
|
78
|
-
if (!removalDate)
|
|
79
|
-
return null;
|
|
80
|
-
const removal = new Date(removalDate);
|
|
81
|
-
const now = new Date();
|
|
82
|
-
const diff = removal.getTime() - now.getTime();
|
|
83
|
-
return Math.ceil(diff / (1000 * 60 * 60 * 24));
|
|
84
|
-
};
|
|
85
|
-
const getUrgencyLevel = (daysRemaining) => {
|
|
86
|
-
if (daysRemaining === null)
|
|
87
|
-
return 'low';
|
|
88
|
-
if (daysRemaining < 0)
|
|
89
|
-
return 'critical';
|
|
90
|
-
if (daysRemaining < 30)
|
|
91
|
-
return 'critical';
|
|
92
|
-
if (daysRemaining < warnDaysBeforeRemoval)
|
|
93
|
-
return 'high';
|
|
94
|
-
return 'medium';
|
|
95
|
-
};
|
|
96
|
-
return {
|
|
97
|
-
MemberExpression(node) {
|
|
98
|
-
if (node.property.type !== 'Identifier')
|
|
99
|
-
return;
|
|
100
|
-
const apiName = node.property.name;
|
|
101
|
-
const deprecatedApi = apis.find((api) => api.name === apiName);
|
|
102
|
-
if (!deprecatedApi)
|
|
103
|
-
return;
|
|
104
|
-
const daysRemaining = calculateDaysRemaining(deprecatedApi.removalDate);
|
|
105
|
-
const urgency = getUrgencyLevel(daysRemaining);
|
|
106
|
-
context.report({
|
|
107
|
-
node,
|
|
108
|
-
messageId: 'deprecatedAPI',
|
|
109
|
-
data: {
|
|
110
|
-
apiName: deprecatedApi.name,
|
|
111
|
-
replacement: deprecatedApi.replacement,
|
|
112
|
-
deprecatedSince: deprecatedApi.deprecatedSince,
|
|
113
|
-
daysRemaining: String(daysRemaining ?? 'Unknown'),
|
|
114
|
-
urgency: urgency.toUpperCase(),
|
|
115
|
-
migrationGuide: deprecatedApi.migrationGuide || 'See documentation',
|
|
116
|
-
},
|
|
117
|
-
suggest: [
|
|
118
|
-
{
|
|
119
|
-
messageId: 'useReplacement',
|
|
120
|
-
data: { replacement: deprecatedApi.replacement },
|
|
121
|
-
fix: (fixer) => {
|
|
122
|
-
return fixer.replaceText(node.property, deprecatedApi.replacement);
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
],
|
|
126
|
-
});
|
|
127
|
-
},
|
|
128
|
-
CallExpression(node) {
|
|
129
|
-
if (node.callee.type !== 'Identifier')
|
|
130
|
-
return;
|
|
131
|
-
const apiName = node.callee.name;
|
|
132
|
-
const deprecatedApi = apis.find((api) => api.name === apiName);
|
|
133
|
-
if (!deprecatedApi)
|
|
134
|
-
return;
|
|
135
|
-
const daysRemaining = calculateDaysRemaining(deprecatedApi.removalDate);
|
|
136
|
-
const urgency = getUrgencyLevel(daysRemaining);
|
|
137
|
-
context.report({
|
|
138
|
-
node,
|
|
139
|
-
messageId: 'deprecatedAPI',
|
|
140
|
-
data: {
|
|
141
|
-
apiName: deprecatedApi.name,
|
|
142
|
-
replacement: deprecatedApi.replacement,
|
|
143
|
-
deprecatedSince: deprecatedApi.deprecatedSince,
|
|
144
|
-
daysRemaining: String(daysRemaining ?? 'Unknown'),
|
|
145
|
-
urgency: urgency.toUpperCase(),
|
|
146
|
-
migrationGuide: deprecatedApi.migrationGuide || 'See documentation',
|
|
147
|
-
},
|
|
148
|
-
suggest: [
|
|
149
|
-
{
|
|
150
|
-
messageId: 'useReplacement',
|
|
151
|
-
data: { replacement: deprecatedApi.replacement },
|
|
152
|
-
fix: (fixer) => {
|
|
153
|
-
return fixer.replaceText(node.callee, deprecatedApi.replacement);
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
],
|
|
157
|
-
});
|
|
158
|
-
},
|
|
159
|
-
};
|
|
160
|
-
},
|
|
161
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noDeprecatedApi=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.noDeprecatedApi=(0,eslint_devkit_2.createRule)({name:"no-deprecated-api",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-conventions/docs/rules/no-deprecated-api.md",description:"Prevent usage of deprecated APIs with migration context",cwe:"CWE-1078",cvss:7.5},fixable:"code",hasSuggestions:true,messages:{deprecatedAPI:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.DEPRECATION,issueName:"Deprecated API",cwe:"CWE-1078",description:"Deprecated API detected",severity:"HIGH",fix:"Migrate to recommended alternative with timeline guidance",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference"}),useReplacement:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use Replacement",description:"Replace with recommended API",severity:"LOW",fix:"Replace with {{replacement}}",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference"})},schema:[{type:"object",properties:{apis:{type:"array",items:{type:"object",properties:{name:{type:"string"},replacement:{type:"string"},deprecatedSince:{type:"string"},removalDate:{type:"string"},reason:{type:"string"},migrationGuide:{type:"string"}},required:["name","replacement","deprecatedSince","reason"]}},warnDaysBeforeRemoval:{type:"number",default:90}},additionalProperties:false}]},defaultOptions:[{apis:[],warnDaysBeforeRemoval:90}],create(context){const options=context.options[0]||{};const{apis=[],warnDaysBeforeRemoval=90}=options;if(!apis||apis.length===0){return{}}const calculateDaysRemaining=removalDate=>{if(!removalDate)return null;const removal=new Date(removalDate);const now=new Date;const diff=removal.getTime()-now.getTime();return Math.ceil(diff/(1e3*60*60*24))};const getUrgencyLevel=daysRemaining=>{if(daysRemaining===null)return"low";if(daysRemaining<0)return"critical";if(daysRemaining<30)return"critical";if(daysRemaining<warnDaysBeforeRemoval)return"high";return"medium"};return{MemberExpression(node){if(node.property.type!=="Identifier")return;const apiName=node.property.name;const deprecatedApi=apis.find(api=>api.name===apiName);if(!deprecatedApi)return;const daysRemaining=calculateDaysRemaining(deprecatedApi.removalDate);const urgency=getUrgencyLevel(daysRemaining);context.report({node,messageId:"deprecatedAPI",data:{apiName:deprecatedApi.name,replacement:deprecatedApi.replacement,deprecatedSince:deprecatedApi.deprecatedSince,daysRemaining:String(daysRemaining??"Unknown"),urgency:urgency.toUpperCase(),migrationGuide:deprecatedApi.migrationGuide||"See documentation"},suggest:[{messageId:"useReplacement",data:{replacement:deprecatedApi.replacement},fix:fixer=>{return fixer.replaceText(node.property,deprecatedApi.replacement)}}]})},CallExpression(node){if(node.callee.type!=="Identifier")return;const apiName=node.callee.name;const deprecatedApi=apis.find(api=>api.name===apiName);if(!deprecatedApi)return;const daysRemaining=calculateDaysRemaining(deprecatedApi.removalDate);const urgency=getUrgencyLevel(daysRemaining);context.report({node,messageId:"deprecatedAPI",data:{apiName:deprecatedApi.name,replacement:deprecatedApi.replacement,deprecatedSince:deprecatedApi.deprecatedSince,daysRemaining:String(daysRemaining??"Unknown"),urgency:urgency.toUpperCase(),migrationGuide:deprecatedApi.migrationGuide||"See documentation"},suggest:[{messageId:"useReplacement",data:{replacement:deprecatedApi.replacement},fix:fixer=>{return fixer.replaceText(node.callee,deprecatedApi.replacement)}}]})}}}});
|