wrec 0.24.10 → 0.24.11
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 +1 -1
- package/scripts/lint.js +9 -44
package/package.json
CHANGED
package/scripts/lint.js
CHANGED
|
@@ -918,7 +918,9 @@ function getComponentPropertyMaps(filePath, sourceText, seen = new Set()) {
|
|
|
918
918
|
seen.add(resolved);
|
|
919
919
|
|
|
920
920
|
const text = sourceText ?? fs.readFileSync(resolved, 'utf8');
|
|
921
|
-
const scriptKind = resolved.endsWith('.ts')
|
|
921
|
+
const scriptKind = resolved.endsWith('.ts')
|
|
922
|
+
? ts.ScriptKind.TS
|
|
923
|
+
: ts.ScriptKind.JS;
|
|
922
924
|
const sourceFile = ts.createSourceFile(
|
|
923
925
|
resolved,
|
|
924
926
|
text,
|
|
@@ -961,51 +963,11 @@ function getComponentPropertyMaps(filePath, sourceText, seen = new Set()) {
|
|
|
961
963
|
return propertyMaps;
|
|
962
964
|
}
|
|
963
965
|
|
|
964
|
-
function findWrecClass(sourceFile, checker) {
|
|
965
|
-
let found;
|
|
966
|
-
|
|
967
|
-
function visit(node) {
|
|
968
|
-
if (found) return;
|
|
969
|
-
if (ts.isClassDeclaration(node) && node.name) {
|
|
970
|
-
const heritage = node.heritageClauses?.find(
|
|
971
|
-
clause => clause.token === ts.SyntaxKind.ExtendsKeyword
|
|
972
|
-
);
|
|
973
|
-
const typeNode = heritage?.types[0];
|
|
974
|
-
if (typeNode) {
|
|
975
|
-
const baseType = checker.getTypeAtLocation(typeNode.expression);
|
|
976
|
-
const baseSymbol = baseType.symbol ?? baseType.aliasSymbol;
|
|
977
|
-
if (baseSymbol?.getName() === 'Wrec') {
|
|
978
|
-
found = node;
|
|
979
|
-
return;
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
ts.forEachChild(node, visit);
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
visit(sourceFile);
|
|
987
|
-
return found;
|
|
988
|
-
}
|
|
989
|
-
|
|
990
966
|
function formatLocation(location) {
|
|
991
967
|
if (!location) return '';
|
|
992
968
|
return `:${location.line + 1}:${location.character + 1}`;
|
|
993
969
|
}
|
|
994
970
|
|
|
995
|
-
function getArgPaths() {
|
|
996
|
-
const [, , filePath, ...rest] = process.argv;
|
|
997
|
-
if (rest.length > 0) {
|
|
998
|
-
fail('usage: node scripts/wrec-lint.js [file.js|file.ts]');
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
try {
|
|
1002
|
-
if (filePath) return [validateFilePath(filePath)];
|
|
1003
|
-
return findWrecFiles(process.cwd());
|
|
1004
|
-
} catch (error) {
|
|
1005
|
-
fail(error instanceof Error ? error.message : String(error));
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
971
|
function getExpressionText(sourceFile, expression) {
|
|
1010
972
|
return expression.getText(sourceFile).trim();
|
|
1011
973
|
}
|
|
@@ -1181,7 +1143,9 @@ function isNumericLikeType(type) {
|
|
|
1181
1143
|
|
|
1182
1144
|
function isWrecComponentFile(filePath) {
|
|
1183
1145
|
const sourceText = fs.readFileSync(filePath, 'utf8');
|
|
1184
|
-
const scriptKind = filePath.endsWith('.ts')
|
|
1146
|
+
const scriptKind = filePath.endsWith('.ts')
|
|
1147
|
+
? ts.ScriptKind.TS
|
|
1148
|
+
: ts.ScriptKind.JS;
|
|
1185
1149
|
const sourceFile = ts.createSourceFile(
|
|
1186
1150
|
filePath,
|
|
1187
1151
|
sourceText,
|
|
@@ -1472,7 +1436,6 @@ function validateDefaultValue(checker, typeExpression, valueExpression) {
|
|
|
1472
1436
|
|
|
1473
1437
|
const typeKind = typeExpressionKind(typeExpression);
|
|
1474
1438
|
const valueType = checker.getTypeAtLocation(valueExpression);
|
|
1475
|
-
const typeName = typeKind ?? typeExpression.getText();
|
|
1476
1439
|
const valueTypeName = checker.typeToString(valueType);
|
|
1477
1440
|
|
|
1478
1441
|
if (typeKind === 'String') {
|
|
@@ -1753,7 +1716,9 @@ function validateHtmlNesting(node, findings) {
|
|
|
1753
1716
|
findings.invalidHtmlNesting.push(
|
|
1754
1717
|
`<${tagName}> must be nested inside ${[...allowedParents]
|
|
1755
1718
|
.map(name => `<${name}>`)
|
|
1756
|
-
.join(
|
|
1719
|
+
.join(
|
|
1720
|
+
' or '
|
|
1721
|
+
)}, but parent is ${parentTagName ? `<${parentTagName}>` : 'the document root'}`
|
|
1757
1722
|
);
|
|
1758
1723
|
}
|
|
1759
1724
|
|