Skip to content

Commit

Permalink
feat: support ESLint 8.x (#108)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Requires Node@^12.22.0 || ^14.17.0 || >=16.0.0
  • Loading branch information
MichaelDeBoey authored Nov 16, 2021
1 parent bb510a5 commit 6f67ec6
Show file tree
Hide file tree
Showing 6 changed files with 1,734 additions and 2,590 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version: 2
defaults: &defaults
working_directory: ~/repo
docker:
- image: circleci/node:10
- image: circleci/node:12

jobs:
test:
Expand Down
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"rules": {
"camelcase": "off",
"no-plusplus": "off",
"import/extensions": "off"
"import/extensions": "off",
"no-shadow": "off",
"@typescript-eslint/no-shadow": "error"
}
}
],
Expand Down
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,26 @@
"eslint": ">=0.8.0"
},
"devDependencies": {
"@types/eslint": "^7.2.0",
"@types/jest": "^26.0.0",
"@types/node": "^14.0.13",
"@typescript-eslint/eslint-plugin": "^3.4.0",
"@typescript-eslint/parser": "^3.4.0",
"eslint": "^7.3.1",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-config-prettier": "^6.11.0",
"eslint-import-resolver-typescript": "^2.0.0",
"eslint-plugin-import": "^2.21.2",
"eslint-plugin-jest": "^23.17.1",
"@types/eslint": "^7.29.0",
"@types/jest": "^27.0.2",
"@types/node": "^16.11.7",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"eslint": "^8.2.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.3.0",
"eslint-import-resolver-typescript": "^2.5.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jest": "^25.2.4",
"eslint-plugin-jest-formatting": "file:.",
"eslint-plugin-prettier": "^3.1.4",
"jest": "^26.1.0",
"prettier": "2.0.5",
"typescript": "^3.9.5",
"ts-jest": "^26.1.1"
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.3.1",
"prettier": "2.4.1",
"typescript": "^4.4.4",
"ts-jest": "^27.0.7"
},
"engines": {
"node": "^10.12.0 || >=12.0.0"
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
"license": "MIT"
}
4 changes: 3 additions & 1 deletion src/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ export const getPaddingLineSequences = (

if (nextNode.loc.start.line - prevToken.loc.end.line >= 2) {
do {
const token = sourceCode.getTokenAfter(prevToken, { includeComments });
const token = sourceCode.getTokenAfter(prevToken, {
includeComments,
}) as AST.Token;

if (token.loc.start.line - prevToken.loc.end.line >= 2) {
pairs.push([prevToken, token]);
Expand Down
85 changes: 42 additions & 43 deletions src/rules/padding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,13 @@ export const enum PaddingType {
Always,
}

type PaddingTester = (
prevNode: Node,
nextNode: Node,
paddingContext: PaddingContext,
) => void;

// A configuration object for padding type and the two statement types
export interface Config {
paddingType: PaddingType;
prevStatementType: StatementTypes;
nextStatementType: StatementTypes;
}

// Tracks position in scope and prevNode. Used to compare current and prev node
// and then to walk back up to the parent scope or down into the next one.
// And so on...
interface Scope {
upper: Scope | null;
prevNode: Node | null;
}

interface ScopeInfo {
prevNode: Node | null;
enter: () => void;
Expand All @@ -76,6 +62,20 @@ interface PaddingContext {
configs: Config[];
}

type PaddingTester = (
prevNode: Node,
nextNode: Node,
paddingContext: PaddingContext,
) => void;

// Tracks position in scope and prevNode. Used to compare current and prev node
// and then to walk back up to the parent scope or down into the next one.
// And so on...
interface Scope {
upper: Scope | null;
prevNode: Node | null;
}

// Creates a StatementTester to test an ExpressionStatement's first token name
const createTokenTester = (tokenName: string): StatementTester => {
return (node: Node, sourceCode: SourceCode): boolean => {
Expand Down Expand Up @@ -143,35 +143,34 @@ const paddingAlwaysTester = (
message: 'Expected blank line before this statement.',
fix(fixer: Rule.RuleFixer): Rule.Fix {
let prevToken = astUtils.getActualLastToken(sourceCode, prevNode);
const nextToken =
sourceCode.getFirstTokenBetween(prevToken, nextNode, {
includeComments: true,
/**
* Skip the trailing comments of the previous node.
* This inserts a blank line after the last trailing comment.
*
* For example:
*
* foo(); // trailing comment.
* // comment.
* bar();
*
* Get fixed to:
*
* foo(); // trailing comment.
*
* // comment.
* bar();
*/
filter(token: AST.Token): boolean {
if (astUtils.areTokensOnSameLine(prevToken, token)) {
prevToken = token;
return false;
}

return true;
},
}) || nextNode;
const nextToken = (sourceCode.getFirstTokenBetween(prevToken, nextNode, {
includeComments: true,
/**
* Skip the trailing comments of the previous node.
* This inserts a blank line after the last trailing comment.
*
* For example:
*
* foo(); // trailing comment.
* // comment.
* bar();
*
* Get fixed to:
*
* foo(); // trailing comment.
*
* // comment.
* bar();
*/
filter(token: AST.Token): boolean {
if (astUtils.areTokensOnSameLine(prevToken, token)) {
prevToken = token;
return false;
}

return true;
},
}) || nextNode) as AST.Token;

const insertText = astUtils.areTokensOnSameLine(prevToken, nextToken)
? '\n\n'
Expand Down
Loading

0 comments on commit 6f67ec6

Please sign in to comment.