Skip to content

Commit

Permalink
feat: support ESLint 8.x
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 committed Nov 14, 2021
1 parent bb510a5 commit da5c29d
Show file tree
Hide file tree
Showing 5 changed files with 1,689 additions and 2,593 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
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.28.2",
"@types/jest": "^27.0.2",
"@types/node": "^16.11.7",
"@typescript-eslint/eslint-plugin": "^5.3.1",
"@typescript-eslint/parser": "^5.3.1",
"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.2",
"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
93 changes: 46 additions & 47 deletions src/rules/padding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { AST, Rule, SourceCode } from 'eslint';
import { Node } from 'estree';
import * as astUtils from '../ast-utils';

// Statement types we'll respond to
export const enum StatementType {
// eslint-disable-next-line no-shadow
export const enum StatementType { // Statement types we'll respond to
Any,
AfterAllToken,
AfterEachToken,
Expand All @@ -36,33 +36,19 @@ type StatementTypes = StatementType | StatementType[];

type StatementTester = (node: Node, sourceCode: SourceCode) => boolean;

// Padding type to apply between statements
export const enum PaddingType {
// eslint-disable-next-line no-shadow
export const enum PaddingType { // Padding type to apply between statements
Any,
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 da5c29d

Please sign in to comment.