Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.

Commit 1917763

Browse files
makotomJosh Goldberg
authored and
Josh Goldberg
committed
Stricter regex to match only "describe" calls (#465) (#472)
* Proposed fix for issue #465 * Revised tests for the fix of #465
1 parent f4c6aae commit 1917763

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

recommended_ruleset.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ module.exports = {
119119
"jsdoc-format": true,
120120
"max-classes-per-file": [true, 3], // we generally recommend making one public class per file
121121
"max-file-line-count": true,
122-
"max-func-body-length": [true, 100, {"ignore-parameters-to-function-regex": "describe"}],
122+
"max-func-body-length": [true, 100, {"ignore-parameters-to-function-regex": "^describe$"}],
123123
"max-line-length": [true, 140],
124124
"member-access": true,
125125
"member-ordering": [true, { "order": "fields-first" }],

src/maxFuncBodyLengthRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class Rule extends Lint.Rules.AbstractRule {
2222
severity: 'Moderate',
2323
level: 'Opportunity for Excellence',
2424
group: 'Clarity',
25-
recommendation: '[true, 100, {"ignore-parameters-to-function-regex": "describe"}],',
25+
recommendation: '[true, 100, {"ignore-parameters-to-function-regex": "^describe$"}],',
2626
commonWeaknessEnumeration: '398, 710'
2727
};
2828

src/tests/MaxFuncBodyLengthRuleTests.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ describe('maxFuncBodyLengthRule', (): void => {
285285
options = [true,
286286
5, // max length is now 5
287287
{
288-
'ignore-parameters-to-function-regex': 'describe'
288+
'ignore-parameters-to-function-regex': '^describe$'
289289
}
290290
];
291291
});
@@ -314,5 +314,31 @@ describe('maxFuncBodyLengthRule', (): void => {
314314
}); // line 7
315315
`, []);
316316
});
317+
318+
it('should not ignore calls of functions that are not exactly named "describe"', (): void => {
319+
TestHelper.assertViolationsWithOptions(
320+
ruleName,
321+
options,
322+
`
323+
describeThings('something', (): void => {
324+
// line 2
325+
// line 3
326+
// line 4
327+
// line 5
328+
}); // line 6
329+
`, [
330+
{
331+
"failure": "Max arrow function body length exceeded - max: 5, actual: 6",
332+
"name": "file.ts",
333+
"ruleName": "max-func-body-length",
334+
"ruleSeverity": "ERROR",
335+
"startPosition": {
336+
"character": 49,
337+
"line": 2
338+
}
339+
}
340+
]
341+
);
342+
});
317343
});
318344
});

tslint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
true,
6161
100,
6262
{
63-
"ignore-parameters-to-function-regex": "describe"
63+
"ignore-parameters-to-function-regex": "^describe$"
6464
}
6565
],
6666
"max-line-length": [

0 commit comments

Comments
 (0)