Skip to content

Commit 2a8ac30

Browse files
authored
chore: minor tidy up of code (#603)
* test: ensure `cwd` is restored after each test * chore: add `eslint-plugin-eslint-config` * chore: replace `ban-ts-ignore` with `ban-ts-comment` rule * chore: enable `padding-line-between-statements` rule * chore: remove some unneeded conditional checks * chore: use correct jsdoc syntax for optional params
1 parent 0456d2e commit 2a8ac30

25 files changed

+87
-18
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
coverage/
22
lib/
3+
!.eslintrc.js

.eslintrc.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const globals = require('./src/globals.json');
55
module.exports = {
66
parser: require.resolve('@typescript-eslint/parser'),
77
extends: [
8+
'plugin:eslint-config/rc',
89
'plugin:eslint-plugin/recommended',
910
'plugin:eslint-comments/recommended',
1011
'plugin:node/recommended',
@@ -13,6 +14,7 @@ module.exports = {
1314
'prettier/@typescript-eslint',
1415
],
1516
plugins: [
17+
'eslint-config',
1618
'eslint-plugin',
1719
'eslint-comments',
1820
'node',
@@ -30,7 +32,7 @@ module.exports = {
3032
rules: {
3133
'@typescript-eslint/array-type': ['error', { default: 'array-simple' }],
3234
'@typescript-eslint/no-require-imports': 'error',
33-
'@typescript-eslint/ban-ts-ignore': 'warn',
35+
'@typescript-eslint/ban-ts-comment': 'warn',
3436
'@typescript-eslint/ban-types': 'error',
3537
'@typescript-eslint/no-unused-vars': 'error',
3638
'eslint-comments/no-unused-disable': 'error',
@@ -58,6 +60,18 @@ module.exports = {
5860
'error',
5961
{ alphabetize: { order: 'asc' }, 'newlines-between': 'never' },
6062
],
63+
'padding-line-between-statements': [
64+
'error',
65+
{ blankLine: 'always', prev: '*', next: 'return' },
66+
{ blankLine: 'always', prev: ['const', 'let', 'var'], next: '*' },
67+
{
68+
blankLine: 'any',
69+
prev: ['const', 'let', 'var'],
70+
next: ['const', 'let', 'var'],
71+
},
72+
{ blankLine: 'always', prev: 'directive', next: '*' },
73+
{ blankLine: 'any', prev: 'directive', next: 'directive' },
74+
],
6175
},
6276
overrides: [
6377
{

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
"eslint": "^5.1.0 || ^6.0.0",
110110
"eslint-config-prettier": "^6.5.0",
111111
"eslint-plugin-eslint-comments": "^3.1.2",
112+
"eslint-plugin-eslint-config": "^1.0.2",
112113
"eslint-plugin-eslint-plugin": "^2.0.0",
113114
"eslint-plugin-import": "^2.20.2",
114115
"eslint-plugin-node": "^11.0.0",

src/__tests__/rules.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ describe('rules', () => {
3636

3737
it('should have the correct amount of rules', () => {
3838
const { length } = ruleNames;
39+
3940
if (length !== numberOfRules) {
4041
throw new Error(
4142
`There should be exactly ${numberOfRules} rules, but there are ${length}. If you've added a new rule, please update this number.`,
@@ -65,6 +66,7 @@ describe('rules', () => {
6566
allConfigRules.forEach(rule => {
6667
const ruleNamePrefix = 'jest/';
6768
const ruleName = rule.slice(ruleNamePrefix.length);
69+
6870
expect(rule.startsWith(ruleNamePrefix)).toBe(true);
6971
expect(ruleNames).toContain(ruleName);
7072
// eslint-disable-next-line @typescript-eslint/no-require-imports

src/rules/expect-expect.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function matchesAssertFunctionName(
3131
.split('.')
3232
.map(x => {
3333
if (x === '**') return '[a-z\\.]*';
34+
3435
return x.replace(/\*/gu, '[a-z]*');
3536
})
3637
.join('\\.')}(\\.|$)`,
@@ -97,6 +98,7 @@ export default createRule<
9798
return {
9899
CallExpression(node) {
99100
const name = getNodeName(node.callee);
101+
100102
if (name === TestCaseName.it || name === TestCaseName.test) {
101103
unchecked.push(node);
102104
} else if (

src/rules/lowercase-name.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const jestFunctionName = (
4343
allowedPrefixes: readonly string[],
4444
) => {
4545
const description = getStringValue(node.arguments[0]);
46+
4647
if (allowedPrefixes.some(name => description.startsWith(name))) {
4748
return null;
4849
}

src/rules/no-alias-methods.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export default createRule({
4545
}
4646

4747
const alias = matcher.name;
48+
4849
if (alias in methodNames) {
4950
const canonical = methodNames[alias];
5051

src/rules/no-duplicate-hooks.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default createRule({
2424
defaultOptions: [],
2525
create(context) {
2626
const hookContexts = [newHookContext()];
27+
2728
return {
2829
CallExpression(node) {
2930
if (isDescribe(node)) {
@@ -32,6 +33,7 @@ export default createRule({
3233

3334
if (isHook(node)) {
3435
const currentLayer = hookContexts[hookContexts.length - 1];
36+
3537
currentLayer[node.callee.name] += 1;
3638
if (currentLayer[node.callee.name] > 1) {
3739
context.report({

src/rules/no-focused-tests.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ interface ConcurrentExpression extends TSESTree.MemberExpressionComputedName {
2424
const isConcurrentExpression = (
2525
expression: TSESTree.MemberExpression,
2626
): expression is ConcurrentExpression =>
27-
expression.type === AST_NODE_TYPES.MemberExpression &&
2827
isSupportedAccessor(expression.property, TestCaseProperty.concurrent) &&
2928
!!expression.parent &&
3029
expression.parent.type === AST_NODE_TYPES.MemberExpression;
@@ -72,6 +71,7 @@ export default createRule({
7271
isCallToFocusedTestFunction(callee.object)
7372
) {
7473
context.report({ messageId: 'focusedTest', node: callee.object });
74+
7575
return;
7676
}
7777

@@ -83,11 +83,13 @@ export default createRule({
8383
messageId: 'focusedTest',
8484
node: callee.object.property,
8585
});
86+
8687
return;
8788
}
8889

8990
if (isCallToTestOnlyFunction(callee)) {
9091
context.report({ messageId: 'focusedTest', node: callee.property });
92+
9193
return;
9294
}
9395
}

src/rules/no-identical-title.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ export default createRule({
3636
defaultOptions: [],
3737
create(context) {
3838
const contexts = [newDescribeContext()];
39+
3940
return {
4041
CallExpression(node) {
4142
const currentLayer = contexts[contexts.length - 1];
43+
4244
if (isDescribe(node)) {
4345
contexts.push(newDescribeContext());
4446
}
4547
const [argument] = node.arguments;
48+
4649
if (!argument || !isStringNode(argument)) {
4750
return;
4851
}

0 commit comments

Comments
 (0)