@bigbinary/eslint-plugin-neeto 2.0.0 → 2.0.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.js +103 -74
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -286,7 +286,7 @@
|
|
|
286
286
|
}
|
|
287
287
|
});
|
|
288
288
|
|
|
289
|
-
var version = "
|
|
289
|
+
var version = "2.0.0";
|
|
290
290
|
var packageJson = {
|
|
291
291
|
version: version};
|
|
292
292
|
|
|
@@ -567,7 +567,7 @@
|
|
|
567
567
|
});
|
|
568
568
|
|
|
569
569
|
const getIndentation = (node, context) => {
|
|
570
|
-
const indentLevel = context.
|
|
570
|
+
const indentLevel = context.sourceCode.getFirstToken(node).loc.start.column;
|
|
571
571
|
return " ".repeat(indentLevel);
|
|
572
572
|
};
|
|
573
573
|
|
|
@@ -582,7 +582,7 @@
|
|
|
582
582
|
},
|
|
583
583
|
create: context => ({
|
|
584
584
|
Property(node) {
|
|
585
|
-
if (!context.
|
|
585
|
+
if (!context.filename.endsWith("package.json") || node.key.value !== "devDependencies") {
|
|
586
586
|
return;
|
|
587
587
|
}
|
|
588
588
|
PACKAGES_TO_CHECK.forEach(packageName => {
|
|
@@ -679,7 +679,7 @@
|
|
|
679
679
|
* @param {Object} node - AST node
|
|
680
680
|
* @returns the source code corresponding to the supplied node.
|
|
681
681
|
*/
|
|
682
|
-
const getCode$1 = (context, node) => context.
|
|
682
|
+
const getCode$1 = (context, node) => context.sourceCode.text.substr(node.range[0], node.range[1] - node.range[0]);
|
|
683
683
|
|
|
684
684
|
/**
|
|
685
685
|
* Checks if the specified package is imported or not
|
|
@@ -687,8 +687,25 @@
|
|
|
687
687
|
* @param {Object} context eslint context
|
|
688
688
|
* @returns an array containing the filename and the extension
|
|
689
689
|
*/
|
|
690
|
+
/**
|
|
691
|
+
* Location for a problem reported on the whole file (the Program node).
|
|
692
|
+
* ESLint 10 makes Program span the entire source, leading comments included,
|
|
693
|
+
* so a report on it lands on line 1 and a `// eslint-disable-next-line` above
|
|
694
|
+
* the first statement stops covering it. Starting at the first token keeps the
|
|
695
|
+
* ESLint 9 location on both versions.
|
|
696
|
+
* @param {Object} context eslint context
|
|
697
|
+
* @param {Object} programNode the Program node
|
|
698
|
+
* @returns {Object} loc to pass to context.report
|
|
699
|
+
*/
|
|
700
|
+
const getFileReportLoc = (context, programNode) => {
|
|
701
|
+
const [firstToken] = context.sourceCode.ast.tokens;
|
|
702
|
+
return firstToken ? {
|
|
703
|
+
start: firstToken.loc.start,
|
|
704
|
+
end: programNode.loc.end
|
|
705
|
+
} : programNode.loc;
|
|
706
|
+
};
|
|
690
707
|
const getFilenameAndExtension = context => {
|
|
691
|
-
const fullFilename = context.
|
|
708
|
+
const fullFilename = context.filename.replace(/.*\//, "");
|
|
692
709
|
const splitFilename = fullFilename.split(".");
|
|
693
710
|
const extension = splitFilename.pop();
|
|
694
711
|
return [splitFilename.join("."), extension];
|
|
@@ -708,7 +725,7 @@
|
|
|
708
725
|
* @returns true if file is inside the `apis` directory
|
|
709
726
|
*/
|
|
710
727
|
const isInsideApisDirectory = context => {
|
|
711
|
-
const filename = context.
|
|
728
|
+
const filename = context.filename;
|
|
712
729
|
const apisDirectory = path$1.resolve(APIS_DIRECTORY);
|
|
713
730
|
return filename.startsWith(apisDirectory) && filename !== `${apisDirectory}/axios.js`;
|
|
714
731
|
};
|
|
@@ -719,7 +736,7 @@
|
|
|
719
736
|
* @returns true if file is inside the `components` directory
|
|
720
737
|
*/
|
|
721
738
|
const isInsideComponentsDirectory = context => {
|
|
722
|
-
const filename = context.
|
|
739
|
+
const filename = context.filename;
|
|
723
740
|
const componentsDirectory = path$1.resolve(COMPONENTS_DIRECTORY);
|
|
724
741
|
return filename.startsWith(componentsDirectory);
|
|
725
742
|
};
|
|
@@ -734,7 +751,7 @@
|
|
|
734
751
|
const isGeneratedTranslationFile = context => {
|
|
735
752
|
const [filename, extension] = getFilenameAndExtension(context);
|
|
736
753
|
const translationsDirectory = path$1.resolve(TRANSLATIONS_DIRECTORY);
|
|
737
|
-
return context.
|
|
754
|
+
return context.filename.startsWith(translationsDirectory) && extension === "json" && filename !== TRANSLATION_SOURCE_LOCALE;
|
|
738
755
|
};
|
|
739
756
|
|
|
740
757
|
/**
|
|
@@ -1153,7 +1170,7 @@
|
|
|
1153
1170
|
};
|
|
1154
1171
|
|
|
1155
1172
|
const isInsideRoutesFile$1 = context => {
|
|
1156
|
-
const filename = context.
|
|
1173
|
+
const filename = context.filename;
|
|
1157
1174
|
return filename.endsWith(ROUTES_FILE_PATH);
|
|
1158
1175
|
};
|
|
1159
1176
|
var routesShouldBeDeclaredAndDefaultExported = {
|
|
@@ -1171,9 +1188,17 @@
|
|
|
1171
1188
|
if (isDeclarationPresent) {
|
|
1172
1189
|
const isDefaultExportPresent = node.body.some(neetoCist.matches(DEFAULT_EXPORT_PATTERN));
|
|
1173
1190
|
if (isDefaultExportPresent) return;
|
|
1174
|
-
context.report(
|
|
1191
|
+
context.report({
|
|
1192
|
+
node,
|
|
1193
|
+
loc: getFileReportLoc(context, node),
|
|
1194
|
+
message: ROUTES_SHOULD_USE_DEFAULT_EXPORT
|
|
1195
|
+
});
|
|
1175
1196
|
} else {
|
|
1176
|
-
context.report(
|
|
1197
|
+
context.report({
|
|
1198
|
+
node,
|
|
1199
|
+
loc: getFileReportLoc(context, node),
|
|
1200
|
+
message: ROUTES_CONSTANT_SHOULD_BE_DECLARED
|
|
1201
|
+
});
|
|
1177
1202
|
}
|
|
1178
1203
|
}
|
|
1179
1204
|
})
|
|
@@ -1184,7 +1209,7 @@
|
|
|
1184
1209
|
return text.substring(0, 1).toLowerCase() + text.substring(1);
|
|
1185
1210
|
};
|
|
1186
1211
|
const isInsideRoutesFile = context => {
|
|
1187
|
-
const filename = context.
|
|
1212
|
+
const filename = context.filename;
|
|
1188
1213
|
return filename.endsWith(ROUTES_FILE_PATH);
|
|
1189
1214
|
};
|
|
1190
1215
|
const isParam = e => e?.startsWith(":");
|
|
@@ -1268,7 +1293,7 @@
|
|
|
1268
1293
|
},
|
|
1269
1294
|
create: context => ({
|
|
1270
1295
|
VariableDeclaration(node) {
|
|
1271
|
-
if (!context.
|
|
1296
|
+
if (!context.filename.endsWith(ROUTES_FILE_PATH)) return;
|
|
1272
1297
|
if (neetoCist.matches(DECALARATION_PATTERN$1, node)) {
|
|
1273
1298
|
checkRoutes(context, node.declarations[0].init);
|
|
1274
1299
|
}
|
|
@@ -1276,7 +1301,7 @@
|
|
|
1276
1301
|
})
|
|
1277
1302
|
};
|
|
1278
1303
|
|
|
1279
|
-
const getCode = (context, start, length) => context.
|
|
1304
|
+
const getCode = (context, start, length) => context.sourceCode.text.substr(start, length);
|
|
1280
1305
|
const replacer$2 = nodeReplacerWithImports(ramda.assocPath(["source", "value"], "neetocommons/utils", IMPORT_DECLARATION));
|
|
1281
1306
|
var useCommonRoutes = {
|
|
1282
1307
|
meta: {
|
|
@@ -1539,7 +1564,7 @@
|
|
|
1539
1564
|
},
|
|
1540
1565
|
create: context => ({
|
|
1541
1566
|
VariableDeclaration(node) {
|
|
1542
|
-
if (!isExcludedFile(CONSTANTS_FILES, context.
|
|
1567
|
+
if (!isExcludedFile(CONSTANTS_FILES, context.filename) && neetoCist.matches(CONSTANT_DECLARATION_PATTERN, node)) {
|
|
1543
1568
|
const constantName = node.declarations[0].id.name;
|
|
1544
1569
|
context.report(node, moveToConstantsJs(constantName));
|
|
1545
1570
|
}
|
|
@@ -1575,12 +1600,12 @@
|
|
|
1575
1600
|
fixable: "whitespace"
|
|
1576
1601
|
},
|
|
1577
1602
|
create: context => {
|
|
1578
|
-
const prettierConfig = getPrettierConfig(context.
|
|
1603
|
+
const prettierConfig = getPrettierConfig(context.filename);
|
|
1579
1604
|
return {
|
|
1580
1605
|
ObjectExpression(node) {
|
|
1581
|
-
if (isExcludedFile(EXCLUDED_FILES, context.
|
|
1606
|
+
if (isExcludedFile(EXCLUDED_FILES, context.filename)) return;
|
|
1582
1607
|
if (!neetoCist.matches(OBJECT_EXPRESSION_PATTERN$1, node)) return;
|
|
1583
|
-
const sourceCode = context.
|
|
1608
|
+
const sourceCode = context.sourceCode;
|
|
1584
1609
|
const hasComments = neetoCist.isNotEmpty(sourceCode.getCommentsInside(node));
|
|
1585
1610
|
if (hasComments) return;
|
|
1586
1611
|
const openingBraceLine = node.loc.start.line;
|
|
@@ -1784,7 +1809,7 @@
|
|
|
1784
1809
|
}
|
|
1785
1810
|
},
|
|
1786
1811
|
create: context => {
|
|
1787
|
-
const allImports = getAllImports(context.
|
|
1812
|
+
const allImports = getAllImports(context.sourceCode.ast);
|
|
1788
1813
|
const neetouiFormName = getLocalNameOfImport(allImports, "NEETOUI_FORM");
|
|
1789
1814
|
const formikName = getLocalNameOfImport(allImports, "FORMIK");
|
|
1790
1815
|
const useFormikName = getLocalNameOfImport(allImports, "USE_FORMIK");
|
|
@@ -3523,7 +3548,7 @@
|
|
|
3523
3548
|
},
|
|
3524
3549
|
create: context => ({
|
|
3525
3550
|
Property(node) {
|
|
3526
|
-
if (!context.
|
|
3551
|
+
if (!context.filename.endsWith("package.json") || node.key.value !== DEPENDENCY_TYPE.peerDependencies) {
|
|
3527
3552
|
return;
|
|
3528
3553
|
}
|
|
3529
3554
|
const peerDependencies = findDependencies(node, DEPENDENCY_TYPE.peerDependencies);
|
|
@@ -5429,7 +5454,7 @@
|
|
|
5429
5454
|
[CASE_STYLES.snake]: SNAKE_CASE_REGEX
|
|
5430
5455
|
};
|
|
5431
5456
|
|
|
5432
|
-
const isInsideBaseDirectory = context => context.
|
|
5457
|
+
const isInsideBaseDirectory = context => context.filename.startsWith(context.options[0].basePath);
|
|
5433
5458
|
const asArray = item => {
|
|
5434
5459
|
if (!item) return [];
|
|
5435
5460
|
return Array.isArray(item) ? item : new Array(item);
|
|
@@ -5439,7 +5464,7 @@
|
|
|
5439
5464
|
return CASE_REGEXES[caseStyle]?.test(text) ?? true;
|
|
5440
5465
|
};
|
|
5441
5466
|
const findMatchedConfig = (context, configs) => {
|
|
5442
|
-
const fullFilePath = context.
|
|
5467
|
+
const fullFilePath = context.filename;
|
|
5443
5468
|
const basePath = context.options[0].basePath;
|
|
5444
5469
|
return configs.find(config => {
|
|
5445
5470
|
const isIncluded = asArray(config.includes).some(pathPattern => minimatch(fullFilePath, basePath + pathPattern));
|
|
@@ -5454,6 +5479,7 @@
|
|
|
5454
5479
|
if (!isCaseMatching(filename, filenameCase)) {
|
|
5455
5480
|
context.report({
|
|
5456
5481
|
node,
|
|
5482
|
+
loc: getFileReportLoc(context, node),
|
|
5457
5483
|
message: filenameShouldBe(filenameCase)
|
|
5458
5484
|
});
|
|
5459
5485
|
}
|
|
@@ -5552,7 +5578,7 @@
|
|
|
5552
5578
|
if (!defaultExportNode) return;
|
|
5553
5579
|
const exportedObjectName = defaultExportNode.declaration?.name;
|
|
5554
5580
|
if (!exportedObjectName) return;
|
|
5555
|
-
const pathKeys = context.
|
|
5581
|
+
const pathKeys = context.filename.split(/\.|\//g).slice(0, -1);
|
|
5556
5582
|
const pathString = filename === "index" ? pathKeys.slice(0, -1).join("") : pathKeys.join("");
|
|
5557
5583
|
const isNameMatches = pathString.endsWith(exportedObjectName);
|
|
5558
5584
|
if (isNameMatches) return;
|
|
@@ -7336,7 +7362,7 @@
|
|
|
7336
7362
|
context,
|
|
7337
7363
|
node
|
|
7338
7364
|
}) => {
|
|
7339
|
-
const sourceCode = context.
|
|
7365
|
+
const sourceCode = context.sourceCode;
|
|
7340
7366
|
const historyMethodCalls = findMatchingNodesDeep(node, HISTORY_METHODS_PATTERN);
|
|
7341
7367
|
const historyMethodCall = historyMethodCalls[0];
|
|
7342
7368
|
const historyMethodArguments = historyMethodCall.arguments;
|
|
@@ -7400,7 +7426,7 @@
|
|
|
7400
7426
|
return;
|
|
7401
7427
|
}
|
|
7402
7428
|
if (isNotPartOfOnClickHandler(node)) return;
|
|
7403
|
-
const sourceCode = context.
|
|
7429
|
+
const sourceCode = context.sourceCode;
|
|
7404
7430
|
reportSuggestion$1({
|
|
7405
7431
|
context,
|
|
7406
7432
|
historyMethodCall,
|
|
@@ -7696,7 +7722,7 @@
|
|
|
7696
7722
|
// Do not replace this with `isInsideApisDirectory` since this rule should include axios.js
|
|
7697
7723
|
// `isInsideApisDirectory` returns false for apis/axios.js
|
|
7698
7724
|
const apisFolder = path$1.resolve(aliases?.apis || APIS_DIRECTORY);
|
|
7699
|
-
if (context.
|
|
7725
|
+
if (context.filename.startsWith(apisFolder)) return;
|
|
7700
7726
|
if (!isPackageImported(context, node, "axios")) return;
|
|
7701
7727
|
context.report(node, NO_AXIOS_IMPORT_OUTSIDE_APIS_MESSAGE);
|
|
7702
7728
|
}
|
|
@@ -7776,7 +7802,7 @@
|
|
|
7776
7802
|
node,
|
|
7777
7803
|
message: NO_BUILD_URL_CALL_WITH_EMPTY_PARAMS,
|
|
7778
7804
|
fix(fixer) {
|
|
7779
|
-
const sourceCode = context.
|
|
7805
|
+
const sourceCode = context.sourceCode;
|
|
7780
7806
|
const firstArgText = sourceCode.getText(node.arguments[0]);
|
|
7781
7807
|
return fixer.replaceText(node, firstArgText);
|
|
7782
7808
|
}
|
|
@@ -7839,7 +7865,7 @@
|
|
|
7839
7865
|
},
|
|
7840
7866
|
value: {
|
|
7841
7867
|
type: TYPES.JSX_EXPRESSION_CONTAINER,
|
|
7842
|
-
expression: expression => isConditionAndIsOpenValueSame(context.
|
|
7868
|
+
expression: expression => isConditionAndIsOpenValueSame(context.sourceCode.getTokens(expression), context.sourceCode.getTokens(conditionalExpression))
|
|
7843
7869
|
}
|
|
7844
7870
|
});
|
|
7845
7871
|
const isOpenValueInSpreadPropsPattern = (context, conditionalExpression) => ({
|
|
@@ -7852,7 +7878,7 @@
|
|
|
7852
7878
|
type: TYPES.IDENTIFIER,
|
|
7853
7879
|
name: "isOpen"
|
|
7854
7880
|
},
|
|
7855
|
-
value: value => isConditionAndIsOpenValueSame(context.
|
|
7881
|
+
value: value => isConditionAndIsOpenValueSame(context.sourceCode.getTokens(value), context.sourceCode.getTokens(conditionalExpression))
|
|
7856
7882
|
})
|
|
7857
7883
|
}
|
|
7858
7884
|
});
|
|
@@ -8020,6 +8046,7 @@
|
|
|
8020
8046
|
if (isGeneratedTranslationFile(context)) {
|
|
8021
8047
|
context.report({
|
|
8022
8048
|
node,
|
|
8049
|
+
loc: getFileReportLoc(context, node),
|
|
8023
8050
|
message: NO_EDITS_TO_GENERATED_TRANSLATION_FILES
|
|
8024
8051
|
});
|
|
8025
8052
|
}
|
|
@@ -8516,7 +8543,7 @@
|
|
|
8516
8543
|
message: NO_UNNECESSARY_CLASSNAMES,
|
|
8517
8544
|
fix(fixer) {
|
|
8518
8545
|
const singleClass = node.value.expression.arguments[0];
|
|
8519
|
-
let classText = context.
|
|
8546
|
+
let classText = context.sourceCode.getText(singleClass);
|
|
8520
8547
|
if (singleClass.type === TYPES.TEMPLATE_LITERAL) {
|
|
8521
8548
|
classText = `{${classText}}`;
|
|
8522
8549
|
}
|
|
@@ -8592,7 +8619,7 @@
|
|
|
8592
8619
|
if (!isFinalIfBeforeBooleanReturn(ifConditionNode, lastStatement, !value)) {
|
|
8593
8620
|
return;
|
|
8594
8621
|
}
|
|
8595
|
-
const condition = context.
|
|
8622
|
+
const condition = context.sourceCode.getText(ifConditionNode.test);
|
|
8596
8623
|
const returnStatementWithCondition = value ? `return ${condition};` : `return !(${condition});`;
|
|
8597
8624
|
const commonDescriptor = {
|
|
8598
8625
|
message: canBeReplacedWith(returnStatementWithCondition),
|
|
@@ -9027,14 +9054,14 @@
|
|
|
9027
9054
|
const prop = properties[index];
|
|
9028
9055
|
const propType = prop.type;
|
|
9029
9056
|
if (propType === TYPES.PROPERTY) {
|
|
9030
|
-
const propText = context.
|
|
9057
|
+
const propText = context.sourceCode.getText(prop);
|
|
9031
9058
|
propsToSort.push(propText);
|
|
9032
9059
|
} else if (propType === TYPES.SPREAD_ELEMENT) {
|
|
9033
9060
|
if (neetoCist.isNotEmpty(propsToSort)) {
|
|
9034
9061
|
sortedProps.push(propsToSort.sort());
|
|
9035
9062
|
propsToSort = [];
|
|
9036
9063
|
}
|
|
9037
|
-
const spreadElement = context.
|
|
9064
|
+
const spreadElement = context.sourceCode.getText(prop.argument);
|
|
9038
9065
|
sortedProps.push(spreadElement);
|
|
9039
9066
|
}
|
|
9040
9067
|
}
|
|
@@ -9077,10 +9104,10 @@
|
|
|
9077
9104
|
} else {
|
|
9078
9105
|
previousNode = node.name;
|
|
9079
9106
|
}
|
|
9080
|
-
return fixer.removeRange([context.
|
|
9107
|
+
return fixer.removeRange([context.sourceCode.getIndexFromLoc({
|
|
9081
9108
|
line: previousNode.loc.end.line,
|
|
9082
9109
|
column: previousNode.loc.end.column
|
|
9083
|
-
}), context.
|
|
9110
|
+
}), context.sourceCode.getIndexFromLoc({
|
|
9084
9111
|
line: endNode.loc.end.line,
|
|
9085
9112
|
column: endNode.loc.end.column
|
|
9086
9113
|
})]);
|
|
@@ -9128,9 +9155,9 @@
|
|
|
9128
9155
|
fix: fixer => {
|
|
9129
9156
|
const mergedProperties = adjacentSpreadAttributes.map(item => {
|
|
9130
9157
|
if (neetoCist.matches(OTHER_PROPS, item)) {
|
|
9131
|
-
return `...${context.
|
|
9158
|
+
return `...${context.sourceCode.getText(item.argument)}`;
|
|
9132
9159
|
}
|
|
9133
|
-
return item.argument.properties.map(item => context.
|
|
9160
|
+
return item.argument.properties.map(item => context.sourceCode.getText(item)).join(", ");
|
|
9134
9161
|
}).join(", ");
|
|
9135
9162
|
const fixToAddProperties = fixer.insertTextAfter(ramda.last(adjacentSpreadAttributes), `\n{...{ ${mergedProperties} }}`);
|
|
9136
9163
|
isAdjacentAttributesFixApplied = true;
|
|
@@ -9172,7 +9199,7 @@
|
|
|
9172
9199
|
fix: fixer => {
|
|
9173
9200
|
const fix = spreadAttributesWithoutOtherProps.flatMap(errorNode => {
|
|
9174
9201
|
let fixToAddProperties = null;
|
|
9175
|
-
const properties = errorNode.argument.properties.map(item => context.
|
|
9202
|
+
const properties = errorNode.argument.properties.map(item => context.sourceCode.getText(item)).join(", ");
|
|
9176
9203
|
let closestNode = getClosestNode(errorNode, spreadAttributes);
|
|
9177
9204
|
const isClosestNodeNotAdjacent = closestNode && errorNode.range[1] !== closestNode.range[0];
|
|
9178
9205
|
if (isClosestNodeNotAdjacent) {
|
|
@@ -9233,13 +9260,13 @@
|
|
|
9233
9260
|
}, attributes);
|
|
9234
9261
|
const indexToInsert = findIndexToInsert(nodeIndex, attributes);
|
|
9235
9262
|
if (indexToInsert === nodeIndex) return;
|
|
9236
|
-
const indentLevel = context.
|
|
9263
|
+
const indentLevel = context.sourceCode.getFirstToken(attributes[0]).loc.start.column;
|
|
9237
9264
|
context.report({
|
|
9238
9265
|
node,
|
|
9239
9266
|
message: MOVE_SPREAD_ATTRIBUTES_TO_TOP,
|
|
9240
9267
|
fix: fixer => {
|
|
9241
9268
|
const removeNode = fixer.remove(node);
|
|
9242
|
-
const moveNode = fixer.insertTextBefore(attributes[indexToInsert], `${context.
|
|
9269
|
+
const moveNode = fixer.insertTextBefore(attributes[indexToInsert], `${context.sourceCode.getText(node)}\n${" ".repeat(indentLevel)}`);
|
|
9243
9270
|
return [moveNode, removeNode];
|
|
9244
9271
|
}
|
|
9245
9272
|
});
|
|
@@ -9372,8 +9399,8 @@
|
|
|
9372
9399
|
} else {
|
|
9373
9400
|
fixToRemoveErrorNode = fixer.remove(node);
|
|
9374
9401
|
}
|
|
9375
|
-
const indentLevel = context.
|
|
9376
|
-
const propertyValue = context.
|
|
9402
|
+
const indentLevel = context.sourceCode.getFirstToken(node.parent.attributes[0]).loc.start.column;
|
|
9403
|
+
const propertyValue = context.sourceCode.getText(property.value);
|
|
9377
9404
|
const fixToAddProperty = positionToInsert === "below" ? fixer.insertTextAfter(node, `\n${" ".repeat(indentLevel)}${property.key.name}={${propertyValue}}`) : fixer.insertTextBefore(node, `${property.key.name}={${propertyValue}}\n${" ".repeat(indentLevel)}`);
|
|
9378
9405
|
return [fixToRemoveComma, fixToRemoveErrorNode, fixToAddProperty].filter(Boolean);
|
|
9379
9406
|
}
|
|
@@ -10172,7 +10199,7 @@
|
|
|
10172
10199
|
},
|
|
10173
10200
|
create: context => ({
|
|
10174
10201
|
Program(node) {
|
|
10175
|
-
const filePath = context.
|
|
10202
|
+
const filePath = context.filename;
|
|
10176
10203
|
if (!filePath.includes(REACT_QUERY_DIRECTORY)) return;
|
|
10177
10204
|
if (filePath.endsWith(FILENAME_SUFFIX)) return;
|
|
10178
10205
|
if (WHITELISTED_FOLDER_NAMES.includes(getFolderName(filePath))) return;
|
|
@@ -10180,6 +10207,7 @@
|
|
|
10180
10207
|
if (WHITELISTED_FILE_NAMES.includes(fileName)) return;
|
|
10181
10208
|
context.report({
|
|
10182
10209
|
node,
|
|
10210
|
+
loc: getFileReportLoc(context, node),
|
|
10183
10211
|
message: FILES_INSIDE_REACT_QUERY_FOLDER_SHOULD_END_WITH_API
|
|
10184
10212
|
});
|
|
10185
10213
|
}
|
|
@@ -10192,7 +10220,7 @@
|
|
|
10192
10220
|
return false;
|
|
10193
10221
|
};
|
|
10194
10222
|
const isInsideReactQueryDirectory = context => {
|
|
10195
|
-
const filename = context.
|
|
10223
|
+
const filename = context.filename;
|
|
10196
10224
|
const reactQueryDirectory = path$1.resolve(REACT_QUERY_DIRECTORY);
|
|
10197
10225
|
return filename.startsWith(reactQueryDirectory);
|
|
10198
10226
|
};
|
|
@@ -10297,6 +10325,7 @@
|
|
|
10297
10325
|
if (!declarator) {
|
|
10298
10326
|
context.report({
|
|
10299
10327
|
node: programNode,
|
|
10328
|
+
loc: getFileReportLoc(context, programNode),
|
|
10300
10329
|
message: helpUrlsFileMustExportBaseUrl(HELP_URLS_FILENAME, HELP_DOCS_BASE_URL_CONSTANT_NAME)
|
|
10301
10330
|
});
|
|
10302
10331
|
return false;
|
|
@@ -10402,7 +10431,7 @@
|
|
|
10402
10431
|
|
|
10403
10432
|
// Check 3: If it's a template literal, it must use permalinks.
|
|
10404
10433
|
if (init.type === TYPES.TEMPLATE_LITERAL) {
|
|
10405
|
-
const fullUrlString = context.
|
|
10434
|
+
const fullUrlString = context.sourceCode.getText(init);
|
|
10406
10435
|
if (ARTICLE_LINK_REGEX.test(fullUrlString)) {
|
|
10407
10436
|
context.report({
|
|
10408
10437
|
node: declarator,
|
|
@@ -10468,7 +10497,7 @@
|
|
|
10468
10497
|
* e.g., `const link = "https://neetochathelp.neetokb.com/p/123";`
|
|
10469
10498
|
*/
|
|
10470
10499
|
const checkForHardcodedHelpUrls = (context, node) => {
|
|
10471
|
-
const value = node.type === TYPES.LITERAL ? node.value : context.
|
|
10500
|
+
const value = node.type === TYPES.LITERAL ? node.value : context.sourceCode.getText(node);
|
|
10472
10501
|
if (typeof value !== "string") {
|
|
10473
10502
|
return;
|
|
10474
10503
|
}
|
|
@@ -10505,7 +10534,7 @@
|
|
|
10505
10534
|
fixable: "code"
|
|
10506
10535
|
},
|
|
10507
10536
|
create(context) {
|
|
10508
|
-
const filename = context.
|
|
10537
|
+
const filename = context.filename;
|
|
10509
10538
|
if (filename.endsWith(HELP_URLS_FILENAME)) {
|
|
10510
10539
|
return {
|
|
10511
10540
|
"Program:exit"(programNode) {
|
|
@@ -10665,7 +10694,7 @@
|
|
|
10665
10694
|
node,
|
|
10666
10695
|
fixer
|
|
10667
10696
|
}) => {
|
|
10668
|
-
const urlString = context.
|
|
10697
|
+
const urlString = context.sourceCode.getText(urlNode);
|
|
10669
10698
|
const fixForParams = getFixForParams({
|
|
10670
10699
|
urlNode,
|
|
10671
10700
|
urlString,
|
|
@@ -10862,13 +10891,13 @@
|
|
|
10862
10891
|
|
|
10863
10892
|
const getFixString = (context, expressionNode) => {
|
|
10864
10893
|
if (expressionNode.type === TYPES.LOGICAL_EXPRESSION) {
|
|
10865
|
-
const left = context.
|
|
10866
|
-
const right = context.
|
|
10894
|
+
const left = context.sourceCode.getText(expressionNode.left);
|
|
10895
|
+
const right = context.sourceCode.getText(expressionNode.right);
|
|
10867
10896
|
return `classnames({ ${right}: ${left} })`;
|
|
10868
10897
|
}
|
|
10869
|
-
const test = context.
|
|
10870
|
-
const consequent = context.
|
|
10871
|
-
const alternate = context.
|
|
10898
|
+
const test = context.sourceCode.getText(expressionNode.test);
|
|
10899
|
+
const consequent = context.sourceCode.getText(expressionNode.consequent);
|
|
10900
|
+
const alternate = context.sourceCode.getText(expressionNode.alternate);
|
|
10872
10901
|
return `classnames({${consequent}: ${test}, ${alternate}: !(${test})})`;
|
|
10873
10902
|
};
|
|
10874
10903
|
|
|
@@ -11121,7 +11150,7 @@
|
|
|
11121
11150
|
}]))
|
|
11122
11151
|
});
|
|
11123
11152
|
const importExists = (context, functionName) => {
|
|
11124
|
-
const ast = context.
|
|
11153
|
+
const ast = context.sourceCode.ast;
|
|
11125
11154
|
return neetoCist.existsBy(createSubscriptionImportPattern(functionName), ast.body);
|
|
11126
11155
|
};
|
|
11127
11156
|
|
|
@@ -11163,7 +11192,7 @@
|
|
|
11163
11192
|
});
|
|
11164
11193
|
}
|
|
11165
11194
|
if (neetoCist.matches(SUBSCRIPTION_REMOVE_PATTERN, node)) {
|
|
11166
|
-
const replacerText = context.
|
|
11195
|
+
const replacerText = context.sourceCode.getText(node.arguments[0]);
|
|
11167
11196
|
const replacerRange = node.range.splice(0, 2);
|
|
11168
11197
|
return context.report({
|
|
11169
11198
|
node: node.callee,
|
|
@@ -11256,11 +11285,11 @@
|
|
|
11256
11285
|
return;
|
|
11257
11286
|
}
|
|
11258
11287
|
const fix = fixer => {
|
|
11259
|
-
const condition = context.
|
|
11260
|
-
const consequent = context.
|
|
11288
|
+
const condition = context.sourceCode.getText(node.test);
|
|
11289
|
+
const consequent = context.sourceCode.getText(node.consequent).replace(/^\{|\}$/g, "");
|
|
11261
11290
|
let alternate = "return;";
|
|
11262
11291
|
if (node.alternate && isReturnBlock(node.alternate)) {
|
|
11263
|
-
alternate = context.
|
|
11292
|
+
alternate = context.sourceCode.getText(node.alternate);
|
|
11264
11293
|
if (node.alternate.type === TYPES.RETURN_STATEMENT) {
|
|
11265
11294
|
alternate = ensurePunctuation(alternate);
|
|
11266
11295
|
}
|
|
@@ -11504,7 +11533,7 @@
|
|
|
11504
11533
|
context,
|
|
11505
11534
|
loc
|
|
11506
11535
|
}) => {
|
|
11507
|
-
const sourceCode = context.
|
|
11536
|
+
const sourceCode = context.sourceCode;
|
|
11508
11537
|
return [sourceCode.getIndexFromLoc(loc.start), sourceCode.getIndexFromLoc(loc.end)];
|
|
11509
11538
|
};
|
|
11510
11539
|
const getCssProperty = cssClass => {
|
|
@@ -11616,7 +11645,7 @@
|
|
|
11616
11645
|
if (!neetoCist.matches(PRIVATE_ROUTE_PATTERN, node)) return;
|
|
11617
11646
|
const errorNode = neetoCist.findBy(CONDITION_ATTRIBUTE_PATTERN, node.attributes);
|
|
11618
11647
|
const functionArguments = errorNode.value.expression.arguments;
|
|
11619
|
-
const arrayFormat = functionArguments.map(argument => argument.type === TYPES.ARRAY_EXPRESSION ? context.
|
|
11648
|
+
const arrayFormat = functionArguments.map(argument => argument.type === TYPES.ARRAY_EXPRESSION ? context.sourceCode.getText(argument).slice(1, -1) : context.sourceCode.getText(argument)).join(", ");
|
|
11620
11649
|
context.report({
|
|
11621
11650
|
node: errorNode,
|
|
11622
11651
|
message: USE_PERMISSIONS_PROP_IN_PRIVATE_ROUTE,
|
|
@@ -11728,7 +11757,7 @@
|
|
|
11728
11757
|
}
|
|
11729
11758
|
},
|
|
11730
11759
|
create(context) {
|
|
11731
|
-
const sourceCode = context.
|
|
11760
|
+
const sourceCode = context.sourceCode;
|
|
11732
11761
|
return {
|
|
11733
11762
|
CallExpression(node) {
|
|
11734
11763
|
const {
|
|
@@ -11911,7 +11940,7 @@
|
|
|
11911
11940
|
importExists
|
|
11912
11941
|
}) => {
|
|
11913
11942
|
const replaceCallee = fixer.replaceText(node.callee, "useMutationWithInvalidation");
|
|
11914
|
-
const indentLevel = context.
|
|
11943
|
+
const indentLevel = context.sourceCode.getFirstToken(mutationOptions.properties[0]).loc.start.column;
|
|
11915
11944
|
let addKeysToInvalidate;
|
|
11916
11945
|
if (existingKeysToInvalidate) {
|
|
11917
11946
|
addKeysToInvalidate = fixer.insertTextAfter(ramda.last(existingKeysToInvalidate.value.elements), `,${keys}`);
|
|
@@ -11936,8 +11965,8 @@
|
|
|
11936
11965
|
return tokenAfter.value === "," ? fixer.remove(tokenAfter) : null;
|
|
11937
11966
|
};
|
|
11938
11967
|
const getVariables = (context, params) => {
|
|
11939
|
-
let variables = params.arguments[0].elements?.filter(element => element.type !== TYPES.LITERAL && /[a-z]/.test(context.
|
|
11940
|
-
if (!params.arguments[0].elements && /[a-z]/.test(context.
|
|
11968
|
+
let variables = params.arguments[0].elements?.filter(element => element.type !== TYPES.LITERAL && /[a-z]/.test(context.sourceCode.getText(element)));
|
|
11969
|
+
if (!params.arguments[0].elements && /[a-z]/.test(context.sourceCode.getText(params.arguments[0]))) {
|
|
11941
11970
|
variables = params.arguments[0];
|
|
11942
11971
|
}
|
|
11943
11972
|
return variables;
|
|
@@ -11981,7 +12010,7 @@
|
|
|
11981
12010
|
fixer,
|
|
11982
12011
|
mutationOptions,
|
|
11983
12012
|
existingKeysToInvalidate,
|
|
11984
|
-
keys: context.
|
|
12013
|
+
keys: context.sourceCode.getText(params.arguments[0]),
|
|
11985
12014
|
importExists
|
|
11986
12015
|
});
|
|
11987
12016
|
const removeInvalidations = fixer.remove(onSuccess);
|
|
@@ -11999,7 +12028,7 @@
|
|
|
11999
12028
|
return;
|
|
12000
12029
|
}
|
|
12001
12030
|
const otherOptions = neetoCist._removeBy(INVALIDATION_PATTERN, params);
|
|
12002
|
-
const queryClientInOtherOptions = otherOptions?.find(item => context.
|
|
12031
|
+
const queryClientInOtherOptions = otherOptions?.find(item => context.sourceCode.getText(item).includes("queryClient"));
|
|
12003
12032
|
if (queryClientInOtherOptions || neetoCist.findBy(OTHER_QUERY_CLIENT_USAGE_PATTERN, ramda.pluck("expression", invalidations))) {
|
|
12004
12033
|
return;
|
|
12005
12034
|
}
|
|
@@ -12010,7 +12039,7 @@
|
|
|
12010
12039
|
if (neetoCist.isNotPresent(invalidationsWithoutVariables)) {
|
|
12011
12040
|
reportError(context, node);
|
|
12012
12041
|
} else {
|
|
12013
|
-
const keys = ramda.pluck("expression", invalidationsWithoutVariables).flatMap(item => item.arguments.map(arg => context.
|
|
12042
|
+
const keys = ramda.pluck("expression", invalidationsWithoutVariables).flatMap(item => item.arguments.map(arg => context.sourceCode.getText(arg)));
|
|
12014
12043
|
context.report({
|
|
12015
12044
|
node,
|
|
12016
12045
|
message: USE_USE_MUTATION_WITH_INVALIDATION,
|
|
@@ -12084,10 +12113,10 @@
|
|
|
12084
12113
|
|
|
12085
12114
|
const getQueryClientInitializationFix = (context, fixer, body) => {
|
|
12086
12115
|
if (body.type === TYPES.BLOCK_STATEMENT) {
|
|
12087
|
-
const indentLevel = context.
|
|
12116
|
+
const indentLevel = context.sourceCode.getFirstToken(body.body[0]).loc.start.column;
|
|
12088
12117
|
return fixer.insertTextBefore(body.body[0], `const queryClient = useQueryClient();\n${" ".repeat(indentLevel)}`);
|
|
12089
12118
|
}
|
|
12090
|
-
return fixer.replaceText(body, `{ const queryClient = useQueryClient(); return (${context.
|
|
12119
|
+
return fixer.replaceText(body, `{ const queryClient = useQueryClient(); return (${context.sourceCode.getText(body)}) }`);
|
|
12091
12120
|
};
|
|
12092
12121
|
|
|
12093
12122
|
var useUseQueryClientHook = {
|
|
@@ -12102,7 +12131,7 @@
|
|
|
12102
12131
|
create: context => ({
|
|
12103
12132
|
VariableDeclarator(node) {
|
|
12104
12133
|
if (node.parent?.parent.type !== TYPES.PROGRAM) return;
|
|
12105
|
-
const text = context.
|
|
12134
|
+
const text = context.sourceCode.getText(node);
|
|
12106
12135
|
if (!text.includes("queryClient.") || text.includes("const queryClient = useQueryClient();")) {
|
|
12107
12136
|
return;
|
|
12108
12137
|
}
|
|
@@ -12165,7 +12194,7 @@
|
|
|
12165
12194
|
const aliases = context.options[0];
|
|
12166
12195
|
if (ramda.isEmpty(aliases) || ramda.isNil(aliases)) return;
|
|
12167
12196
|
const importPath = node.source.value;
|
|
12168
|
-
const importFullPath = importPath.startsWith("../") ? path$1.resolve(context.
|
|
12197
|
+
const importFullPath = importPath.startsWith("../") ? path$1.resolve(context.filename, "../", importPath) : importPath;
|
|
12169
12198
|
const matches = Object.entries(aliases).filter(([, path]) => importFullPath.startsWith(path) && ["/", undefined].includes(importFullPath.split(path)[1][0])).sort((first, second) => first.length - second.length);
|
|
12170
12199
|
if (matches.length === 0) return;
|
|
12171
12200
|
const aliasMatch = matches[matches.length - 1];
|
|
@@ -12213,7 +12242,7 @@
|
|
|
12213
12242
|
if (!watcher) watchJsConfigFile(context.options?.[0]?.jsconfigFilePath);
|
|
12214
12243
|
return {
|
|
12215
12244
|
Property(node) {
|
|
12216
|
-
const filename = context.
|
|
12245
|
+
const filename = context.filename;
|
|
12217
12246
|
const isInsideAliasFile = filename === context.options?.[0]?.aliasFilePath;
|
|
12218
12247
|
if (!isInsideAliasFile) return;
|
|
12219
12248
|
const isInsideAliasProperty = node.parent?.parent?.key?.name === "alias";
|
|
@@ -12872,7 +12901,7 @@
|
|
|
12872
12901
|
const programNode = findProgramNode(node);
|
|
12873
12902
|
const importSpecifierNode = findRamdaSpecifiers(programNode);
|
|
12874
12903
|
const comparatorFunctionNode = node.init.arguments[1];
|
|
12875
|
-
const propImportNode = findMatchingNodesDeep(context.
|
|
12904
|
+
const propImportNode = findMatchingNodesDeep(context.sourceCode.ast.body, PROP_IMPORT_PATTERN);
|
|
12876
12905
|
context.report({
|
|
12877
12906
|
node,
|
|
12878
12907
|
message: USE_PROP_FOR_PICKING_SINGLE_ITEM,
|
|
@@ -12912,7 +12941,7 @@
|
|
|
12912
12941
|
node,
|
|
12913
12942
|
message: USE_WITH_IMMUTABLE_ACTIONS_WRAPPER,
|
|
12914
12943
|
fix: fixer => {
|
|
12915
|
-
const argumentsString = argumentsInsideCreate.map(argument => context.
|
|
12944
|
+
const argumentsString = argumentsInsideCreate.map(argument => context.sourceCode.getText(argument)).join(", ");
|
|
12916
12945
|
const fixerArray = [];
|
|
12917
12946
|
const addWrapperFixer = `create(withImmutableActions(${argumentsString}))`;
|
|
12918
12947
|
fixerArray.push(fixer.replaceText(createUsageWithoutWrapper.init, addWrapperFixer));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigbinary/eslint-plugin-neeto",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"scripts": {
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"peerDependencies": {
|
|
91
91
|
"@bigbinary/neeto-cist": "^1.0.3",
|
|
92
92
|
"@bigbinary/neeto-commons-frontend": "4.13.38",
|
|
93
|
-
"eslint": "^9.25.1",
|
|
93
|
+
"eslint": "^9.25.1 || ^10.0.0",
|
|
94
94
|
"i18next": "26.3.4",
|
|
95
95
|
"ramda": "0.29.0"
|
|
96
96
|
}
|