Skip to content

Upgrade typescript-eslint and prettier #92

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ globals: {
}
overrides:
- files: "**/*.ts"
plugins:
- "@typescript-eslint"
parser: "@typescript-eslint/parser"
rules:
"@typescript-eslint/consistent-type-imports": error
no-duplicate-imports: off
"@typescript-eslint/no-duplicate-imports": error
- files: "typings/**"
rules:
node/no-missing-import:
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@types/lodash": "^4.14.120",
"@types/mocha": "^5.2.4",
"@types/node": "^10.12.21",
"@typescript-eslint/eslint-plugin": "^4.9.1",
"@typescript-eslint/parser": "^4.7.0",
"babel-eslint": "^10.0.1",
"chokidar": "^2.0.4",
Expand All @@ -41,6 +42,7 @@
"npm-run-all": "^4.1.5",
"nyc": "^14.0.0",
"opener": "^1.5.1",
"prettier": "^2.2.1",
"rimraf": "^2.6.3",
"rollup": "^1.1.2",
"rollup-plugin-node-resolve": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/ast/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @copyright 2017 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*/
import { Location } from "./locations"
import type { Location } from "./locations"

/**
* Check whether the given value has acorn style location information.
Expand Down
8 changes: 4 additions & 4 deletions src/ast/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* @copyright 2017 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*/
import { ScopeManager } from "eslint-scope"
import { ParseError } from "./errors"
import { HasLocation } from "./locations"
import { Token } from "./tokens"
import type { ScopeManager } from "eslint-scope"
import type { ParseError } from "./errors"
import type { HasLocation } from "./locations"
import type { Token } from "./tokens"

//------------------------------------------------------------------------------
// Common
Expand Down
2 changes: 1 addition & 1 deletion src/ast/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @copyright 2017 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*/
import { HasLocation } from "./locations"
import type { HasLocation } from "./locations"

/**
* Tokens.
Expand Down
5 changes: 3 additions & 2 deletions src/ast/traverse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* @copyright 2017 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*/
import Evk, { VisitorKeys } from "eslint-visitor-keys"
import { Node } from "./nodes"
import type { VisitorKeys } from "eslint-visitor-keys"
import Evk from "eslint-visitor-keys"
import type { Node } from "./nodes"

//------------------------------------------------------------------------------
// Helpers
Expand Down
10 changes: 3 additions & 7 deletions src/common/fix-locations.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import {
ESLintExtendedProgram,
LocationRange,
Node,
traverseNodes,
} from "../ast"
import { LocationCalculator } from "./location-calculator"
import type { ESLintExtendedProgram, LocationRange, Node } from "../ast"
import { traverseNodes } from "../ast"
import type { LocationCalculator } from "./location-calculator"

/**
* Do post-process of parsing an expression.
Expand Down
2 changes: 1 addition & 1 deletion src/common/location-calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* See LICENSE file in root directory for full license.
*/
import sortedLastIndex from "lodash/sortedLastIndex"
import { HasLocation, Location, ParseError } from "../ast"
import type { HasLocation, Location, ParseError } from "../ast"

/**
* Location calculators.
Expand Down
6 changes: 3 additions & 3 deletions src/html/intermediate-tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
*/
import assert from "assert"
import last from "lodash/last"
import {
import type {
ErrorCode,
HasLocation,
Namespace,
ParseError,
Token,
VAttribute,
} from "../ast"
import { ParseError } from "../ast"
import { debug } from "../common/debug"
import { Tokenizer, TokenizerState, TokenType } from "./tokenizer"
import type { Tokenizer, TokenizerState, TokenType } from "./tokenizer"

const DUMMY_PARENT: any = Object.freeze({})

Expand Down
24 changes: 12 additions & 12 deletions src/html/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@
import assert from "assert"
import last from "lodash/last"
import findLastIndex from "lodash/findLastIndex"
import {
import type {
ErrorCode,
HasLocation,
Namespace,
NS,
ParseError,
Token,
VAttribute,
VDocumentFragment,
VElement,
VExpressionContainer,
} from "../ast"
import { NS, ParseError } from "../ast"
import { debug } from "../common/debug"
import { LocationCalculator } from "../common/location-calculator"
import {
Expand All @@ -37,16 +36,17 @@ import {
HTML_VOID_ELEMENT_TAGS,
SVG_ELEMENT_NAME_MAP,
} from "./util/tag-names"
import {
import type {
IntermediateToken,
IntermediateTokenizer,
EndTag,
Mustache,
StartTag,
Text,
} from "./intermediate-tokenizer"
import { Tokenizer } from "./tokenizer"
import { isSFCFile, ParserOptions } from "../common/parser-options"
import { IntermediateTokenizer } from "./intermediate-tokenizer"
import type { Tokenizer } from "./tokenizer"
import type { ParserOptions } from "../common/parser-options"
import { isSFCFile } from "../common/parser-options"

const DIRECTIVE_NAME = /^(?:v-|[.:@#]).*[^.:@#]$/u
const DT_DD = /^d[dt]$/u
Expand Down Expand Up @@ -83,7 +83,7 @@ function isHTMLIntegrationPoint(element: VElement): boolean {
return (
element.name === "annotation-xml" &&
element.startTag.attributes.some(
a =>
(a) =>
a.directive === false &&
a.key.name === "encoding" &&
a.value != null &&
Expand Down Expand Up @@ -358,7 +358,7 @@ export class Parser {
}

if (name === "template") {
const xmlns = token.attributes.find(a => a.key.name === "xmlns")
const xmlns = token.attributes.find((a) => a.key.name === "xmlns")
const value = xmlns && xmlns.value && xmlns.value.value

if (value === NS.HTML || value === NS.MathML || value === NS.SVG) {
Expand Down Expand Up @@ -462,7 +462,7 @@ export class Parser {
}
const hasVPre =
!this.isInVPreElement &&
token.attributes.some(a => a.key.name === "v-pre")
token.attributes.some((a) => a.key.name === "v-pre")

// Disable expression if v-pre
if (hasVPre) {
Expand Down Expand Up @@ -520,7 +520,7 @@ export class Parser {
if (namespace === NS.HTML) {
if (element.parent.type === "VDocumentFragment") {
const langAttr = element.startTag.attributes.find(
a => !a.directive && a.key.name === "lang",
(a) => !a.directive && a.key.name === "lang",
) as VAttribute | undefined
const lang = langAttr?.value?.value

Expand Down Expand Up @@ -565,7 +565,7 @@ export class Parser {

const i = findLastIndex(
this.elementStack,
el => el.name.toLowerCase() === token.name,
(el) => el.name.toLowerCase() === token.name,
)
if (i === -1) {
this.reportParseError(token, "x-invalid-end-tag")
Expand Down
5 changes: 3 additions & 2 deletions src/html/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import assert from "assert"
import { debug } from "../common/debug"
import { ErrorCode, Namespace, NS, ParseError, Token } from "../ast"
import type { ErrorCode, Namespace, Token } from "../ast"
import { NS, ParseError } from "../ast"
import { alternativeCR } from "./util/alternative-cr"
import { entitySets } from "./util/entities"
import {
Expand Down Expand Up @@ -50,7 +51,7 @@ import {
SOLIDUS,
toLowerCodePoint,
} from "./util/unicode"
import { ParserOptions } from "../common/parser-options"
import type { ParserOptions } from "../common/parser-options"

/**
* Enumeration of token types.
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { LocationCalculator } from "./common/location-calculator"
import { HTMLParser, HTMLTokenizer } from "./html"
import { parseScript, parseScriptElement } from "./script"
import * as services from "./parser-services"
import { ParserOptions } from "./common/parser-options"
import type { ParserOptions } from "./common/parser-options"

const STARTS_WITH_LT = /^\s*</u

Expand Down
25 changes: 14 additions & 11 deletions src/parser-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,30 @@
* @copyright 2017 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*/
import { Rule } from "eslint"
import type { Rule } from "eslint"
import EventEmitter from "events"
import NodeEventGenerator from "./external/node-event-generator"
import TokenStore from "./external/token-store"
import {
traverseNodes,
import type {
ESLintProgram,
VElement,
VDocumentFragment,
VAttribute,
} from "./ast"
import { LocationCalculator } from "./common/location-calculator"
import {
createCustomBlockSharedContext,
import { traverseNodes } from "./ast"
import type { LocationCalculator } from "./common/location-calculator"
import type {
CustomBlockContext,
ESLintCustomBlockParser,
} from "./sfc/custom-block"
import {
createCustomBlockSharedContext,
getCustomBlocks,
getLang,
parseCustomBlockElement,
} from "./sfc/custom-block"
import { isSFCFile, ParserOptions } from "./common/parser-options"
import type { ParserOptions } from "./common/parser-options"
import { isSFCFile } from "./common/parser-options"

//------------------------------------------------------------------------------
// Helpers
Expand Down Expand Up @@ -137,7 +140,7 @@ export function define(
emitters.set(rootAST, emitter)

const programExitHandler = scriptVisitor["Program:exit"]
scriptVisitor["Program:exit"] = node => {
scriptVisitor["Program:exit"] = (node) => {
try {
if (typeof programExitHandler === "function") {
programExitHandler(node)
Expand Down Expand Up @@ -195,7 +198,7 @@ export function define(
}
parserOptions = { ...parserOptions } //eslint-disable-line no-param-reassign
const customBlocks = getCustomBlocks(document).filter(
block =>
(block) =>
block.endTag &&
!block.startTag.attributes.some(
(attr): attr is VAttribute =>
Expand All @@ -214,7 +217,7 @@ export function define(
const visitorFactories = factories

const programExitHandler = scriptVisitor["Program:exit"]
scriptVisitor["Program:exit"] = node => {
scriptVisitor["Program:exit"] = (node) => {
try {
if (typeof programExitHandler === "function") {
programExitHandler(node)
Expand All @@ -223,7 +226,7 @@ export function define(
const lang = getLang(customBlock)

const activeVisitorFactories = visitorFactories.filter(
f => f.test(lang, customBlock),
(f) => f.test(lang, customBlock),
)
if (!activeVisitorFactories.length) {
continue
Expand Down
4 changes: 2 additions & 2 deletions src/script/espree.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Module from "module"
import path from "path"
import { ESLintExtendedProgram, ESLintProgram } from "../ast"
import type { ESLintExtendedProgram, ESLintProgram } from "../ast"

/**
* The interface of a result of ESLint custom parser.
Expand All @@ -23,7 +23,7 @@ const createRequire: (filename: string) => (modname: string) => any =
Module.createRequireFromPath ||
// Polyfill - This is not executed on the tests on node@>=10.
/* istanbul ignore next */
(modname => {
((modname) => {
const mod = new Module(modname)

mod.filename = modname
Expand Down
19 changes: 9 additions & 10 deletions src/script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import first from "lodash/first"
import last from "lodash/last"
import sortedIndexBy from "lodash/sortedIndexBy"
import {
import type {
ESLintArrayPattern,
ESLintCallExpression,
ESLintExpression,
Expand All @@ -20,7 +20,6 @@ import {
ESLintUnaryExpression,
HasLocation,
Node,
ParseError,
Reference,
Token,
Variable,
Expand All @@ -32,14 +31,16 @@ import {
VSlotScopeExpression,
OffsetRange,
} from "../ast"
import { ParseError } from "../ast"
import { debug } from "../common/debug"
import { LocationCalculator } from "../common/location-calculator"
import type { LocationCalculator } from "../common/location-calculator"
import {
analyzeExternalReferences,
analyzeVariablesAndExternalReferences,
} from "./scope-analyzer"
import { ESLintCustomParser, getEspree } from "./espree"
import { ParserOptions } from "../common/parser-options"
import type { ESLintCustomParser } from "./espree"
import { getEspree } from "./espree"
import type { ParserOptions } from "../common/parser-options"
import { fixLocations } from "../common/fix-locations"

// [1] = spacing before the aliases.
Expand Down Expand Up @@ -96,7 +97,7 @@ function getCommaTokenBeforeNode(tokens: Token[], node: Node): Token | null {
let tokenIndex = sortedIndexBy(
tokens as { range: OffsetRange }[],
{ range: node.range },
t => t.range[0],
(t) => t.range[0],
)

while (tokenIndex >= 0) {
Expand Down Expand Up @@ -615,9 +616,7 @@ export function parseExpression(
if (!retB.expression) {
return retB
}
const ret = (retB as unknown) as ExpressionParseResult<
VFilterSequenceExpression
>
const ret = (retB as unknown) as ExpressionParseResult<VFilterSequenceExpression>

ret.expression = {
type: "VFilterSequenceExpression",
Expand Down Expand Up @@ -735,7 +734,7 @@ export function parseVForExpression(
if (replaced) {
const closeOffset = statement.left.range[1] - 1
const open = tokens[0]
const close = tokens.find(t => t.range[0] === closeOffset)
const close = tokens.find((t) => t.range[0] === closeOffset)

if (open != null) {
open.value = "("
Expand Down
Loading