Skip to content

Commit

Permalink
Upgrade to Eslint7
Browse files Browse the repository at this point in the history
  • Loading branch information
saberduck committed Jul 16, 2020
1 parent 7e7a586 commit 8178479
Show file tree
Hide file tree
Showing 16 changed files with 878 additions and 1,162 deletions.
15 changes: 8 additions & 7 deletions eslint-bridge/package.json
Expand Up @@ -24,10 +24,10 @@
"node": ">=6"
},
"devDependencies": {
"@types/eslint": "4.16.3",
"@types/eslint": "7.2.0",
"@types/eslint-scope": "3.7.0",
"@types/esprima": "4.0.2",
"@types/estree": "0.0.39",
"@types/estree": "0.0.45",
"@types/express": "4.16.0",
"@types/jest": "23.3.2",
"@types/node": "13.1.4",
Expand All @@ -40,16 +40,17 @@
"typescript": "3.9.5"
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "2.23.0",
"@typescript-eslint/experimental-utils": "2.23.0",
"@typescript-eslint/parser": "2.23.0",
"@types/json-schema": "7.0.5",
"@typescript-eslint/eslint-plugin": "3.6.1",
"@typescript-eslint/experimental-utils": "^3.6.1",
"@typescript-eslint/parser": "3.6.1",
"babel-eslint": "10.1.0",
"body-parser": "1.18.3",
"builtin-modules": "3.1.0",
"eslint": "5.16.0",
"eslint": "7.4.0",
"eslint-plugin-chai-friendly": "0.5.0",
"eslint-plugin-sonarjs": "0.5.0",
"espree": "5.0.1",
"espree": "7.1.0",
"express": "4.16.3",
"run-node": "1.0.0",
"vue-eslint-parser": "6.0.4"
Expand Down
9 changes: 8 additions & 1 deletion eslint-bridge/src/analyzer.ts
Expand Up @@ -81,6 +81,8 @@ export interface AnalysisResponse {
highlightedSymbols: HighlightedSymbol[];
metrics: Metrics;
cpdTokens: CpdToken[];
parsingTime?: [number, number];
analysisTime?: [number, number];
}

export interface ParsingError {
Expand Down Expand Up @@ -136,9 +138,14 @@ function analyze(input: AnalysisInput, parse: Parse): AnalysisResponse {
if (!fileContent) {
fileContent = getFileContent(input.filePath);
}
const start = process.hrtime();
const result = parse(fileContent, input.filePath, input.tsConfigs);
const parsingTime = process.hrtime(start);
if (result instanceof SourceCode) {
return analyzeFile(result, input);
const start = process.hrtime();
const analysis = analyzeFile(result, input);
const analysisTime = process.hrtime(start);
return { ...analysis, parsingTime, analysisTime };
} else {
return {
...EMPTY_RESPONSE,
Expand Down
2 changes: 1 addition & 1 deletion eslint-bridge/src/rules/no-duplicate-in-composite.ts
Expand Up @@ -44,7 +44,7 @@ export const rule: Rule.RuleModule = {
const groupedTypes: Map<string, Array<TSESTree.Node>> = new Map();

compositeType.types.forEach(typescriptType => {
const nodeValue = sourceCode.getText(typescriptType as estree.Node);
const nodeValue = sourceCode.getText((typescriptType as unknown) as estree.Node);
const nodesWithGivenType = groupedTypes.get(nodeValue);
const nodeType = typescriptType as TSESTree.Node;
if (!nodesWithGivenType) {
Expand Down
3 changes: 2 additions & 1 deletion eslint-bridge/src/rules/no-globals-shadowing.ts
Expand Up @@ -21,6 +21,7 @@

import { Rule } from 'eslint';
import * as estree from 'estree';
import { AssignmentProperty } from 'estree';

const illegalNames = ['eval', 'arguments', 'undefined', 'NaN', 'Infinity'];

Expand Down Expand Up @@ -90,7 +91,7 @@ function reportBadUsage(
break;
case 'ObjectPattern':
node.properties.forEach(prop => {
reportBadUsage(prop.value, buildMessage, context);
reportBadUsage((prop as AssignmentProperty).value, buildMessage, context);
});
break;
case 'ArrayPattern':
Expand Down
2 changes: 1 addition & 1 deletion eslint-bridge/src/rules/no-useless-intersection.ts
Expand Up @@ -50,7 +50,7 @@ export const rule: Rule.RuleModule = {
if (isTypeWithoutMembers(tp, ts)) {
context.report({
message: 'Remove this type without members or change this type intersection.',
node: typeNode as estree.Node,
node: (typeNode as unknown) as estree.Node,
});
}
});
Expand Down
3 changes: 2 additions & 1 deletion eslint-bridge/src/rules/os-command.ts
Expand Up @@ -26,6 +26,7 @@ import {
getModuleNameOfImportedIdentifier,
isIdentifier,
} from './utils';
import { Property } from 'estree';

const EXEC_FUNCTIONS = ['exec', 'execSync'];

Expand Down Expand Up @@ -91,7 +92,7 @@ function containsShellOption(otherArguments: Argument[]) {
return otherArguments.some(
arg =>
arg.type === 'ObjectExpression' &&
arg.properties.some(
(arg.properties as Property[]).some(
({ key, value }) =>
isIdentifier(key, 'shell') && value.type === 'Literal' && value.value === true,
),
Expand Down
2 changes: 1 addition & 1 deletion eslint-bridge/src/rules/prefer-type-guard.ts
Expand Up @@ -118,7 +118,7 @@ function getCastTupleFromMemberExpression(
if (node.type === 'MemberExpression') {
const object = node.object as TSESTree.Node;
if (object.type === 'TSAsExpression' || object.type === 'TSTypeAssertion') {
return [object.expression as estree.Node, object.typeAnnotation as estree.Node];
return [object.expression as estree.Node, (object.typeAnnotation as unknown) as estree.Node];
}
}
return undefined;
Expand Down
7 changes: 5 additions & 2 deletions eslint-bridge/src/rules/shorthand-property-grouping.ts
Expand Up @@ -23,6 +23,7 @@ import { Rule } from 'eslint';
import * as estree from 'estree';
import { toEncodedMessage } from './utils';
import { TSESTree } from '@typescript-eslint/experimental-utils';
import { Property } from 'estree';

export const rule: Rule.RuleModule = {
meta: {
Expand All @@ -45,7 +46,7 @@ export const rule: Rule.RuleModule = {
const secondaryMessages = [];

for (let i = begin; i < end; i++) {
const prop = properties[i];
const prop = properties[i] as Property;
if (prop.shorthand) {
secondaryNodes.push(prop);
secondaryMessages.push(`Move to ${positionMessage}`);
Expand All @@ -70,7 +71,9 @@ export const rule: Rule.RuleModule = {
if (objectExpressionProperties.some(p => p.type !== 'Property')) {
return;
}
const isShorthandPropertyList = objectExpressionProperties.map(p => p.shorthand);
const isShorthandPropertyList = objectExpressionProperties.map(
p => (p as Property).shorthand,
);
const shorthandPropertiesNumber = isShorthandPropertyList.filter(b => b).length;

const numberOfShorthandAtBeginning = getNumberOfTrueAtBeginning(isShorthandPropertyList);
Expand Down
4 changes: 3 additions & 1 deletion eslint-bridge/src/rules/use-type-alias.ts
Expand Up @@ -58,7 +58,9 @@ export const rule: Rule.RuleModule = {
const composite = (node as unknown) as TSESTree.TSUnionType | TSESTree.TSIntersectionType;
if (composite.types.length > TYPE_THRESHOLD) {
const text = composite.types
.map(typeNode => context.getSourceCode().getText(typeNode as estree.Node))
.map(typeNode =>
context.getSourceCode().getText((typeNode as unknown) as estree.Node),
)
.sort((a, b) => a.localeCompare(b))
.join('|');
let occurrences = usage.get(text);
Expand Down
12 changes: 8 additions & 4 deletions eslint-bridge/tests/server.test.ts
Expand Up @@ -197,8 +197,10 @@ describe('server', () => {
}),
'/analyze-js',
);

expect(JSON.parse(response)).toEqual(expectedResponse);
const responseJson = JSON.parse(response);
delete responseJson.analysisTime;
delete responseJson.parsingTime;
expect(responseJson).toEqual(expectedResponse);
});

it('should respond to TypeScript analysis request', async () => {
Expand All @@ -218,8 +220,10 @@ describe('server', () => {
}),
'/analyze-ts',
);

expect(JSON.parse(response)).toEqual(expectedResponse);
const responseJson = JSON.parse(response);
delete responseJson.analysisTime;
delete responseJson.parsingTime;
expect(responseJson).toEqual(expectedResponse);
}, 10_000);

it('should respond OK! when started', done => {
Expand Down

0 comments on commit 8178479

Please sign in to comment.