eslint-plugin-jest-formatting 3.0.0 → 3.1.0

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.
@@ -7,7 +7,7 @@ version: 2
7
7
  defaults: &defaults
8
8
  working_directory: ~/repo
9
9
  docker:
10
- - image: circleci/node:10
10
+ - image: circleci/node:12
11
11
 
12
12
  jobs:
13
13
  test:
package/.eslintrc CHANGED
@@ -20,7 +20,9 @@
20
20
  "rules": {
21
21
  "camelcase": "off",
22
22
  "no-plusplus": "off",
23
- "import/extensions": "off"
23
+ "import/extensions": "off",
24
+ "no-shadow": "off",
25
+ "@typescript-eslint/no-shadow": "error"
24
26
  }
25
27
  }
26
28
  ],
@@ -0,0 +1,71 @@
1
+ # For most projects, this workflow file will not need changing; you simply need
2
+ # to commit it to your repository.
3
+ #
4
+ # You may wish to alter this file to override the set of languages analyzed,
5
+ # or to provide custom queries or build logic.
6
+ #
7
+ # ******** NOTE ********
8
+ # We have attempted to detect the languages in your repository. Please check
9
+ # the `language` matrix defined below to confirm you have the correct set of
10
+ # supported CodeQL languages.
11
+ #
12
+ name: "CodeQL"
13
+
14
+ on:
15
+ push:
16
+ branches: [ master ]
17
+ pull_request:
18
+ # The branches below must be a subset of the branches above
19
+ branches: [ master ]
20
+ schedule:
21
+ - cron: '42 12 * * 5'
22
+
23
+ jobs:
24
+ analyze:
25
+ name: Analyze
26
+ runs-on: ubuntu-latest
27
+ permissions:
28
+ actions: read
29
+ contents: read
30
+ security-events: write
31
+
32
+ strategy:
33
+ fail-fast: false
34
+ matrix:
35
+ language: [ 'javascript' ]
36
+ # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
37
+ # Learn more:
38
+ # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
39
+
40
+ steps:
41
+ - name: Checkout repository
42
+ uses: actions/checkout@v2
43
+
44
+ # Initializes the CodeQL tools for scanning.
45
+ - name: Initialize CodeQL
46
+ uses: github/codeql-action/init@v1
47
+ with:
48
+ languages: ${{ matrix.language }}
49
+ # If you wish to specify custom queries, you can do so here or in a config file.
50
+ # By default, queries listed here will override any specified in a config file.
51
+ # Prefix the list here with "+" to use these queries and those in the config file.
52
+ # queries: ./path/to/local/query, your-org/your-repo/queries@main
53
+
54
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
55
+ # If this step fails, then you should remove it and run the build manually (see below)
56
+ - name: Autobuild
57
+ uses: github/codeql-action/autobuild@v1
58
+
59
+ # ℹ️ Command-line programs to run using the OS shell.
60
+ # 📚 https://git.io/JvXDl
61
+
62
+ # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
63
+ # and modify them (or add more) to build your code if your project
64
+ # uses a compiled language
65
+
66
+ #- run: |
67
+ # make bootstrap
68
+ # make release
69
+
70
+ - name: Perform CodeQL Analysis
71
+ uses: github/codeql-action/analyze@v1
package/lib/ast-utils.js CHANGED
@@ -1,36 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPaddingLineSequences = exports.getActualLastToken = exports.isValidParent = exports.areTokensOnSameLine = exports.isTokenASemicolon = void 0;
4
- exports.isTokenASemicolon = (token) => token.value === ';' && token.type === 'Punctuator';
5
- exports.areTokensOnSameLine = (left, right) => left.loc.end.line === right.loc.start.line;
4
+ const isTokenASemicolon = (token) => token.value === ';' && token.type === 'Punctuator';
5
+ exports.isTokenASemicolon = isTokenASemicolon;
6
+ const areTokensOnSameLine = (left, right) => left.loc.end.line === right.loc.start.line;
7
+ exports.areTokensOnSameLine = areTokensOnSameLine;
6
8
  const STATEMENT_LIST_PARENTS = new Set([
7
9
  'Program',
8
10
  'BlockStatement',
9
11
  'SwitchCase',
10
12
  'SwitchStatement',
11
13
  ]);
12
- exports.isValidParent = (parentType) => {
14
+ const isValidParent = (parentType) => {
13
15
  return STATEMENT_LIST_PARENTS.has(parentType);
14
16
  };
15
- exports.getActualLastToken = (sourceCode, node) => {
17
+ exports.isValidParent = isValidParent;
18
+ const getActualLastToken = (sourceCode, node) => {
16
19
  const semiToken = sourceCode.getLastToken(node);
17
20
  const prevToken = sourceCode.getTokenBefore(semiToken);
18
21
  const nextToken = sourceCode.getTokenAfter(semiToken);
19
22
  const isSemicolonLessStyle = Boolean(prevToken &&
20
23
  nextToken &&
21
24
  prevToken.range[0] >= node.range[0] &&
22
- exports.isTokenASemicolon(semiToken) &&
25
+ (0, exports.isTokenASemicolon)(semiToken) &&
23
26
  semiToken.loc.start.line !== prevToken.loc.end.line &&
24
27
  semiToken.loc.end.line === nextToken.loc.start.line);
25
28
  return isSemicolonLessStyle ? prevToken : semiToken;
26
29
  };
27
- exports.getPaddingLineSequences = (prevNode, nextNode, sourceCode) => {
30
+ exports.getActualLastToken = getActualLastToken;
31
+ const getPaddingLineSequences = (prevNode, nextNode, sourceCode) => {
28
32
  const pairs = [];
29
33
  const includeComments = true;
30
- let prevToken = exports.getActualLastToken(sourceCode, prevNode);
34
+ let prevToken = (0, exports.getActualLastToken)(sourceCode, prevNode);
31
35
  if (nextNode.loc.start.line - prevToken.loc.end.line >= 2) {
32
36
  do {
33
- const token = sourceCode.getTokenAfter(prevToken, { includeComments });
37
+ const token = sourceCode.getTokenAfter(prevToken, {
38
+ includeComments,
39
+ });
34
40
  if (token.loc.start.line - prevToken.loc.end.line >= 2) {
35
41
  pairs.push([prevToken, token]);
36
42
  }
@@ -39,3 +45,4 @@ exports.getPaddingLineSequences = (prevNode, nextNode, sourceCode) => {
39
45
  }
40
46
  return pairs;
41
47
  };
48
+ exports.getPaddingLineSequences = getPaddingLineSequences;
package/lib/index.js CHANGED
@@ -114,14 +114,14 @@ const paddingConfigs = {
114
114
  ],
115
115
  };
116
116
  exports.rules = {
117
- 'padding-around-after-all-blocks': padding_1.createRule(paddingConfigs.afterAll),
118
- 'padding-around-after-each-blocks': padding_1.createRule(paddingConfigs.afterEach),
119
- 'padding-around-before-all-blocks': padding_1.createRule(paddingConfigs.beforeAll),
120
- 'padding-around-before-each-blocks': padding_1.createRule(paddingConfigs.beforeEach),
121
- 'padding-around-describe-blocks': padding_1.createRule(paddingConfigs.describe),
122
- 'padding-around-expect-groups': padding_1.createRule(paddingConfigs.expect),
123
- 'padding-around-test-blocks': padding_1.createRule(paddingConfigs.test),
124
- 'padding-around-all': padding_1.createRule([].concat(...Object.keys(paddingConfigs).map((k) => paddingConfigs[k]))),
117
+ 'padding-around-after-all-blocks': (0, padding_1.createRule)(paddingConfigs.afterAll),
118
+ 'padding-around-after-each-blocks': (0, padding_1.createRule)(paddingConfigs.afterEach),
119
+ 'padding-around-before-all-blocks': (0, padding_1.createRule)(paddingConfigs.beforeAll),
120
+ 'padding-around-before-each-blocks': (0, padding_1.createRule)(paddingConfigs.beforeEach),
121
+ 'padding-around-describe-blocks': (0, padding_1.createRule)(paddingConfigs.describe),
122
+ 'padding-around-expect-groups': (0, padding_1.createRule)(paddingConfigs.expect),
123
+ 'padding-around-test-blocks': (0, padding_1.createRule)(paddingConfigs.test),
124
+ 'padding-around-all': (0, padding_1.createRule)([].concat(...Object.keys(paddingConfigs).map((k) => paddingConfigs[k]))),
125
125
  };
126
126
  exports.configs = {
127
127
  recommended: {
@@ -64,7 +64,7 @@ const paddingAlwaysTester = (prevNode, nextNode, paddingContext) => {
64
64
  message: 'Expected blank line before this statement.',
65
65
  fix(fixer) {
66
66
  let prevToken = astUtils.getActualLastToken(sourceCode, prevNode);
67
- const nextToken = sourceCode.getFirstTokenBetween(prevToken, nextNode, {
67
+ const nextToken = (sourceCode.getFirstTokenBetween(prevToken, nextNode, {
68
68
  includeComments: true,
69
69
  filter(token) {
70
70
  if (astUtils.areTokensOnSameLine(prevToken, token)) {
@@ -73,7 +73,7 @@ const paddingAlwaysTester = (prevNode, nextNode, paddingContext) => {
73
73
  }
74
74
  return true;
75
75
  },
76
- }) || nextNode;
76
+ }) || nextNode);
77
77
  const insertText = astUtils.areTokensOnSameLine(prevToken, nextToken)
78
78
  ? '\n\n'
79
79
  : '\n';
@@ -137,7 +137,7 @@ const verifyNode = (node, paddingContext) => {
137
137
  }
138
138
  scopeInfo.prevNode = node;
139
139
  };
140
- exports.createRule = (configs, deprecated = false) => ({
140
+ const createRule = (configs, deprecated = false) => ({
141
141
  meta: {
142
142
  fixable: 'whitespace',
143
143
  deprecated,
@@ -166,3 +166,4 @@ exports.createRule = (configs, deprecated = false) => ({
166
166
  };
167
167
  },
168
168
  });
169
+ exports.createRule = createRule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-jest-formatting",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "ESLint rules for formatting jest tests",
5
5
  "keywords": [
6
6
  "eslint",
@@ -30,26 +30,26 @@
30
30
  "eslint": ">=0.8.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@types/eslint": "^7.2.0",
34
- "@types/jest": "^26.0.0",
35
- "@types/node": "^14.0.13",
36
- "@typescript-eslint/eslint-plugin": "^3.4.0",
37
- "@typescript-eslint/parser": "^3.4.0",
38
- "eslint": "^7.3.1",
39
- "eslint-config-airbnb-base": "^14.2.0",
40
- "eslint-config-prettier": "^6.11.0",
41
- "eslint-import-resolver-typescript": "^2.0.0",
42
- "eslint-plugin-import": "^2.21.2",
43
- "eslint-plugin-jest": "^23.17.1",
33
+ "@types/eslint": "^7.29.0",
34
+ "@types/jest": "^27.0.2",
35
+ "@types/node": "^16.11.7",
36
+ "@typescript-eslint/eslint-plugin": "^5.4.0",
37
+ "@typescript-eslint/parser": "^5.4.0",
38
+ "eslint": "^8.2.0",
39
+ "eslint-config-airbnb-base": "^15.0.0",
40
+ "eslint-config-prettier": "^8.3.0",
41
+ "eslint-import-resolver-typescript": "^2.5.0",
42
+ "eslint-plugin-import": "^2.25.3",
43
+ "eslint-plugin-jest": "^25.2.4",
44
44
  "eslint-plugin-jest-formatting": "file:.",
45
- "eslint-plugin-prettier": "^3.1.4",
46
- "jest": "^26.1.0",
47
- "prettier": "2.0.5",
48
- "typescript": "^3.9.5",
49
- "ts-jest": "^26.1.1"
45
+ "eslint-plugin-prettier": "^4.0.0",
46
+ "jest": "^27.3.1",
47
+ "prettier": "2.4.1",
48
+ "typescript": "^4.4.4",
49
+ "ts-jest": "^27.0.7"
50
50
  },
51
51
  "engines": {
52
- "node": "^10.12.0 || >=12.0.0"
52
+ "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
53
53
  },
54
54
  "license": "MIT"
55
55
  }
package/src/ast-utils.ts CHANGED
@@ -66,7 +66,9 @@ export const getPaddingLineSequences = (
66
66
 
67
67
  if (nextNode.loc.start.line - prevToken.loc.end.line >= 2) {
68
68
  do {
69
- const token = sourceCode.getTokenAfter(prevToken, { includeComments });
69
+ const token = sourceCode.getTokenAfter(prevToken, {
70
+ includeComments,
71
+ }) as AST.Token;
70
72
 
71
73
  if (token.loc.start.line - prevToken.loc.end.line >= 2) {
72
74
  pairs.push([prevToken, token]);
@@ -42,12 +42,6 @@ export const enum PaddingType {
42
42
  Always,
43
43
  }
44
44
 
45
- type PaddingTester = (
46
- prevNode: Node,
47
- nextNode: Node,
48
- paddingContext: PaddingContext,
49
- ) => void;
50
-
51
45
  // A configuration object for padding type and the two statement types
52
46
  export interface Config {
53
47
  paddingType: PaddingType;
@@ -55,14 +49,6 @@ export interface Config {
55
49
  nextStatementType: StatementTypes;
56
50
  }
57
51
 
58
- // Tracks position in scope and prevNode. Used to compare current and prev node
59
- // and then to walk back up to the parent scope or down into the next one.
60
- // And so on...
61
- interface Scope {
62
- upper: Scope | null;
63
- prevNode: Node | null;
64
- }
65
-
66
52
  interface ScopeInfo {
67
53
  prevNode: Node | null;
68
54
  enter: () => void;
@@ -76,6 +62,20 @@ interface PaddingContext {
76
62
  configs: Config[];
77
63
  }
78
64
 
65
+ type PaddingTester = (
66
+ prevNode: Node,
67
+ nextNode: Node,
68
+ paddingContext: PaddingContext,
69
+ ) => void;
70
+
71
+ // Tracks position in scope and prevNode. Used to compare current and prev node
72
+ // and then to walk back up to the parent scope or down into the next one.
73
+ // And so on...
74
+ interface Scope {
75
+ upper: Scope | null;
76
+ prevNode: Node | null;
77
+ }
78
+
79
79
  // Creates a StatementTester to test an ExpressionStatement's first token name
80
80
  const createTokenTester = (tokenName: string): StatementTester => {
81
81
  return (node: Node, sourceCode: SourceCode): boolean => {
@@ -143,35 +143,34 @@ const paddingAlwaysTester = (
143
143
  message: 'Expected blank line before this statement.',
144
144
  fix(fixer: Rule.RuleFixer): Rule.Fix {
145
145
  let prevToken = astUtils.getActualLastToken(sourceCode, prevNode);
146
- const nextToken =
147
- sourceCode.getFirstTokenBetween(prevToken, nextNode, {
148
- includeComments: true,
149
- /**
150
- * Skip the trailing comments of the previous node.
151
- * This inserts a blank line after the last trailing comment.
152
- *
153
- * For example:
154
- *
155
- * foo(); // trailing comment.
156
- * // comment.
157
- * bar();
158
- *
159
- * Get fixed to:
160
- *
161
- * foo(); // trailing comment.
162
- *
163
- * // comment.
164
- * bar();
165
- */
166
- filter(token: AST.Token): boolean {
167
- if (astUtils.areTokensOnSameLine(prevToken, token)) {
168
- prevToken = token;
169
- return false;
170
- }
171
-
172
- return true;
173
- },
174
- }) || nextNode;
146
+ const nextToken = (sourceCode.getFirstTokenBetween(prevToken, nextNode, {
147
+ includeComments: true,
148
+ /**
149
+ * Skip the trailing comments of the previous node.
150
+ * This inserts a blank line after the last trailing comment.
151
+ *
152
+ * For example:
153
+ *
154
+ * foo(); // trailing comment.
155
+ * // comment.
156
+ * bar();
157
+ *
158
+ * Get fixed to:
159
+ *
160
+ * foo(); // trailing comment.
161
+ *
162
+ * // comment.
163
+ * bar();
164
+ */
165
+ filter(token: AST.Token): boolean {
166
+ if (astUtils.areTokensOnSameLine(prevToken, token)) {
167
+ prevToken = token;
168
+ return false;
169
+ }
170
+
171
+ return true;
172
+ },
173
+ }) || nextNode) as AST.Token;
175
174
 
176
175
  const insertText = astUtils.areTokensOnSameLine(prevToken, nextToken)
177
176
  ? '\n\n'