Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support ESLint 8.x #108

Merged
merged 1 commit into from Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
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
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
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",
MichaelDeBoey marked this conversation as resolved.
Show resolved Hide resolved
"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
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
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