wrec 0.24.7 → 0.24.8

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/scripts/lint.js +28 -0
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "wrec",
3
3
  "description": "a small library that greatly simplifies building web components",
4
4
  "author": "R. Mark Volkmann",
5
- "version": "0.24.7",
5
+ "version": "0.24.8",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
package/scripts/lint.js CHANGED
@@ -4,6 +4,7 @@
4
4
  // - undefined properties accessed in expressions
5
5
  // - undefined instance methods called in expressions
6
6
  // - undefined context functions called in expressions
7
+ // - extra arguments passed to methods and context functions
7
8
  // - incompatible method arguments in expressions
8
9
  // - arithmetic type errors in expressions
9
10
  // - invalid computed property references and calls to non-method members
@@ -173,6 +174,17 @@ function analyzeExpression(
173
174
  .dotDotDotToken
174
175
  );
175
176
 
177
+ if (!isRest && node.arguments.length > parameters.length) {
178
+ node.arguments.slice(parameters.length).forEach((argument, index) => {
179
+ findings.extraArguments.push({
180
+ argument: toUserFacingExpression(argument.getText()),
181
+ argumentIndex: parameters.length + index + 1,
182
+ methodName: toUserFacingExpression(callee.getText()),
183
+ parameterCount: parameters.length
184
+ });
185
+ });
186
+ }
187
+
176
188
  node.arguments.forEach((argument, index) => {
177
189
  let parameterSymbol = parameters[index];
178
190
  let isRestArgument =
@@ -683,6 +695,7 @@ function formatReport(
683
695
  findings.undefinedProperties.length > 0 ||
684
696
  findings.undefinedContextFunctions.length > 0 ||
685
697
  findings.undefinedMethods.length > 0 ||
698
+ findings.extraArguments.length > 0 ||
686
699
  findings.incompatibleArguments.length > 0 ||
687
700
  findings.invalidEventHandlers.length > 0 ||
688
701
  findings.unsupportedHtmlAttributes.length > 0 ||
@@ -801,6 +814,15 @@ function formatReport(
801
814
  findings.invalidUseStateMaps.forEach(message => lines.push(` ${message}`));
802
815
  }
803
816
 
817
+ if (findings.extraArguments.length > 0) {
818
+ lines.push('extra arguments:');
819
+ findings.extraArguments.forEach(finding => {
820
+ lines.push(
821
+ ` ${finding.methodName}: argument ${finding.argumentIndex} "${finding.argument}" exceeds the ${finding.parameterCount}-parameter signature`
822
+ );
823
+ });
824
+ }
825
+
804
826
  if (findings.incompatibleArguments.length > 0) {
805
827
  lines.push('incompatible arguments:');
806
828
  findings.incompatibleArguments.forEach(finding => {
@@ -1177,6 +1199,7 @@ export function lintSource(filePath, sourceText, options = {}) {
1177
1199
  const allMethods = collectClassMethods(classNode);
1178
1200
  const findings = {
1179
1201
  duplicateProperties,
1202
+ extraArguments: [],
1180
1203
  incompatibleArguments: [],
1181
1204
  invalidComputedProperties: [],
1182
1205
  invalidDefaultValues: [],
@@ -1269,6 +1292,11 @@ export function lintSource(filePath, sourceText, options = {}) {
1269
1292
  });
1270
1293
 
1271
1294
  findings.duplicateProperties.sort();
1295
+ findings.extraArguments.sort(
1296
+ (a, b) =>
1297
+ a.methodName.localeCompare(b.methodName) ||
1298
+ a.argumentIndex - b.argumentIndex
1299
+ );
1272
1300
  findings.incompatibleArguments.sort(
1273
1301
  (a, b) =>
1274
1302
  a.methodName.localeCompare(b.methodName) ||