Skip to content

Commit

Permalink
build: replace tslint with eslint (#1382)
Browse files Browse the repository at this point in the history
fixes #1271
  • Loading branch information
bd82 authored Feb 26, 2021
1 parent 5a50819 commit efbc5da
Show file tree
Hide file tree
Showing 77 changed files with 2,023 additions and 1,526 deletions.
69 changes: 69 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
module.exports = {
// Common settings for JS Files.
extends: ["plugin:eslint-comments/recommended", "prettier"],
env: {
es6: true,
commonjs: true,
mocha: true,
node: true
},
globals: {
expect: true,
define: true,
window: true
},
rules: {
"eslint-comments/require-description": ["error", { ignore: [] }]
},
overrides: [
{
// For pure-java script sub-packages and general scripts (in any package).
files: ["*.js"],
extends: ["eslint:recommended"],
excludedFiles: [
"**/vendor/**/*.js",
"**/diagrams/**/*.js",
"**/benchmark_web/**/*.js"
],

parserOptions: {
// The `ecmaVersion` should align to the supported features of our target runtimes (browsers / nodejs / others)
// Consult with: https://kangax.github.io/compat-table/es2016plus/
ecmaVersion: 2017
}
},
{
// For sub-packages using TypeScript (libraries/VSCode Exts) && TypeScript definitions (d.ts)
files: ["*.ts"],
plugins: ["@typescript-eslint"],
parser: "@typescript-eslint/parser",
parserOptions: {
// project: ["./tsconfig.base.json", "./tsconfig.json"],
},
extends: [
"plugin:@typescript-eslint/eslint-recommended"
// "plugin:@typescript-eslint/recommended-requiring-type-checking",
],
rules: {
"@typescript-eslint/no-use-before-define": [
"error",
// These can be safely used before they are defined due to function hoisting in EcmaScript
{ functions: false, classes: false }
]
// TODO: This rule configuration is very useful, attempt to apply it on the existing code base in the future
// "@typescript-eslint/ban-ts-comment": [
// "error",
// {
// // We only allow ts-expect-error comments to enforce removal
// // of outdated suppression comments when the underlying issue has been resolved.
// // https://devblogs.microsoft.com/typescript/announcing-typescript-3-9/#what-about-ts-ignore
// "ts-expect-error": "allow-with-description",
// "ts-ignore": true,
// "ts-nocheck": true,
// "ts-check": true,
// },
// ],
}
}
]
}
3 changes: 3 additions & 0 deletions examples/grammars/css/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ FRAGMENT("spaces", "[ \\t\\r\\n\\f]+")
FRAGMENT("ident", "-?{{nmstart}}{{nmchar}}*")
FRAGMENT("num", "[0-9]+|[0-9]*\\.[0-9]+")

/* eslint-disable no-unused-vars -- tokens are collected in our `createToken` wrapper */
const Whitespace = createToken({
name: "Whitespace",
pattern: MAKE_PATTERN("{{spaces}}"),
Expand Down Expand Up @@ -244,6 +245,8 @@ const Ident = createToken({

const Minus = createToken({ name: "Minus", pattern: /-/ })

/* eslint-enable no-unused-vars -- tokens are collected in our `createToken` wrapper */

const CssLexer = new Lexer(cssTokens)

// ----------------- parser -----------------
Expand Down
12 changes: 9 additions & 3 deletions examples/grammars/ecma5/ecma5_parser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
"use strict"

const { EmbeddedActionsParser, EOF, tokenMatcher } = require("chevrotain")
const {
EmbeddedActionsParser,
EOF,
tokenMatcher,
MismatchedTokenException
} = require("chevrotain")
const tokens = require("./ecma5_tokens")
// for conciseness
const t = tokens
Expand Down Expand Up @@ -689,7 +694,7 @@ class ECMAScript5Parser extends EmbeddedActionsParser {
// there is no danger of inRule recovery (single token insertion/deletion)
// happening in this case because that type of recovery can only happen if CONSUME(...) was invoked.
this.SAVE_ERROR(
new chevrotain.MismatchedTokenException(
new MismatchedTokenException(
"Line Terminator not allowed before Expression in Throw Statement"
// TODO: create line terminator token on the fly?
)
Expand Down Expand Up @@ -865,8 +870,9 @@ class ECMAScript5Parser extends EmbeddedActionsParser {
// the "IN" is only allowed if x is a left hand side expression
// https://www.ecma-international.org/ecma-262/5.1/index.html#sec-12.6
// so this method must verify that the exp parameter fulfills this condition.
// eslint-disable-next-line no-unused-vars -- function signature
canInComeAfterExp(exp) {
// TODO: temp implemntatoin, will always allow IN style iteration for now.
// TODO: temp implementation, will always allow IN style iteration for now.
return true
}

Expand Down
6 changes: 5 additions & 1 deletion examples/grammars/graphql/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
// wrapping in UMD to allow code to work both in node.js
// and in the browser
;(function (root, factory) {
(function (root, factory) {
if (typeof module === "object" && module.exports) {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
Expand Down Expand Up @@ -84,6 +84,8 @@
return newNotTokenCategory
}

/* eslint-disable no-unused-vars -- tokens are collected in our `createToken` wrapper */

// B1 - Ignored-Tokens
// http://facebook.github.io/graphql/June2018/#sec-Appendix-Grammar-Summary.Ignored-Tokens
const WhiteSpace = createToken({
Expand Down Expand Up @@ -116,6 +118,8 @@
group: Lexer.SKIPPED
})

/* eslint-enable no-unused-vars -- tokens are collected in our `createToken` wrapper */

// B2 - Lexical Tokens
// http://facebook.github.io/graphql/June2018/#sec-Appendix-Grammar-Summary.Lexical-Tokens
// Punctuator
Expand Down
2 changes: 1 addition & 1 deletion examples/grammars/tinyc/tinyc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function createToken(options) {
return newToken
}

const WhiteSpace = createToken({
createToken({
name: "WhiteSpace",
pattern: /\s+/,
group: Lexer.SKIPPED
Expand Down
2 changes: 1 addition & 1 deletion examples/implementation_languages/ecma6/ecma6_json.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const JsonLexer = new Lexer(allTokens)

// ----------------- parser -----------------
class JsonParserES6 extends CstParser {
constructor(input) {
constructor() {
super(allTokens)

// not mandatory, using $ (or any other sign) to reduce verbosity (this. this. this. this. .......)
Expand Down
4 changes: 3 additions & 1 deletion examples/lexer/custom_errors/custom_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ const Whitespace = createToken({
})

// A link to the detailed API for the ILexerErrorMessageProvider can be found here:
// https://chevrotain.io/docs/features/custom_errors.htmlconst OyVeyErrorMessageProvider = {
// https://chevrotain.io/docs/features/custom_errors.html
const OyVeyErrorMessageProvider = {
buildUnexpectedCharactersMessage(
fullText,
startOffset,
length,
// eslint-disable-next-line no-unused-vars -- template
line,
// eslint-disable-next-line no-unused-vars -- template
column
) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const Whitespace = createToken({
group: Lexer.SKIPPED
})

keywordsVsIdentifiersLexer = new Lexer([
const keywordsVsIdentifiersLexer = new Lexer([
Whitespace, // Whitespace is very common in most languages so placing it first generally speeds up the lexing.

While, // the actual keywords (While/For/Do) must appear BEFORE the Identifier Token as they are all a valid prefix of it's PATTERN.
Expand Down
1 change: 0 additions & 1 deletion examples/parser/content_assist/content_assist_simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* "Public sta" --> ["static"]
* "call f" --> ["foo"] // assuming foo is in the symbol table.
*/
const _ = require("lodash")
const { createToken, Lexer, CstParser } = require("chevrotain")

const A = createToken({ name: "A", pattern: /A/ })
Expand Down
3 changes: 2 additions & 1 deletion examples/parser/custom_errors/custom_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const myErrorProvider = {

// ----------------- parser -----------------
class CustomErrorsParser extends CstParser {
constructor(input) {
constructor() {
super(allTokens, {
// passing our custom error message provider
errorMessageProvider: myErrorProvider
Expand Down Expand Up @@ -124,6 +124,7 @@ function parseStartingWithRule(ruleName) {
// setting a new input will RESET the parser instance's state.
parser.input = lexResult.tokens
// just invoke which ever rule you want as the start rule. its all just plain javascript...
// eslint-disable-next-line no-unused-vars -- template
const cst = parser[ruleName]()

// we are only interested in the errors in this scenario.
Expand Down
1 change: 0 additions & 1 deletion examples/tutorial/step1_lexing/step1_lexing_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use strict"
const expect = require("chai").expect
const _ = require("lodash")
const tokenMatcher = require("chevrotain").tokenMatcher
const lex = require("./step1_lexing").lex
const tokenVocabulary = require("./step1_lexing").tokenVocabulary
Expand Down
1 change: 0 additions & 1 deletion examples/tutorial/step2_parsing/step2_parsing_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use strict"
const expect = require("chai").expect
const _ = require("lodash")
const parse = require("./step2_parsing").parse

describe("Chevrotain Tutorial", () => {
Expand Down
1 change: 0 additions & 1 deletion examples/tutorial/step3_actions/step3_actions_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use strict"
const expect = require("chai").expect
const _ = require("lodash")
const toAstVisitor = require("./step3a_actions_visitor").toAst
const toAstEmbedded = require("./step3b_actions_embedded").toAst

Expand Down
16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
"scripts": {
"lerna:version": "yarn && lerna version",
"lerna:publish": "lerna publish from-git --yes --no-verify-access",
"ci": "npm-run-all format:validate build test",
"ci": "npm-run-all format:validate lint:validate build test",
"build": "lerna run build",
"test": "lerna run test",
"format:fix": "prettier --ignore-path .gitignore --write \"**/*.@(ts|js|json|md|yml)\"",
"format:validate": "prettier --ignore-path .gitignore --check \"**/*.@(ts|js|json|md|yml)\""
"format:validate": "prettier --ignore-path .gitignore --check \"**/*.@(ts|js|json|md|yml)\"",
"lint:fix": "eslint . --ext=js,ts --fix --max-warnings=0 --ignore-path=.gitignore",
"lint:validate": "eslint . --ext=js,ts --max-warnings=0 --ignore-path=.gitignore"
},
"prettier": {
"endOfLine": "lf",
Expand All @@ -30,6 +32,9 @@
"lint-staged": {
"*.{ts,js,json,md}": [
"prettier --write"
],
"*.{ts,js}": [
"eslint --fix --max-warnings=0 --ignore-pattern=!.*"
]
},
"config": {
Expand All @@ -54,6 +59,11 @@
"shx": "^0.3.2",
"cz-conventional-changelog": "3.3.0",
"@commitlint/cli": "12.0.0",
"@commitlint/config-conventional": "12.0.0"
"@commitlint/config-conventional": "12.0.0",
"eslint": "7.18.0",
"@typescript-eslint/parser": "4.14.0",
"@typescript-eslint/eslint-plugin": "4.15.0",
"eslint-config-prettier": "7.2.0",
"eslint-plugin-eslint-comments": "3.2.0"
}
}
2 changes: 1 addition & 1 deletion packages/chevrotain/diagrams/src/diagrams_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
var Optional = railroad.Optional
var OneOrMore = railroad.OneOrMore
var ZeroOrMore = railroad.ZeroOrMore
var Terminal = railroad.Terminal
// var Terminal = railroad.Terminal
var NonTerminal = railroad.NonTerminal

/**
Expand Down
4 changes: 1 addition & 3 deletions packages/chevrotain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"homepage": "https://chevrotain.io/docs/",
"scripts": {
"---------- CI FLOWS --------": "",
"build": "npm-run-all clean lint compile build:esm dts api-site:build bundle",
"build": "npm-run-all clean compile build:esm dts api-site:build bundle",
"build:esm": "npm-run-all clean:esm compile:esm",
"test": "npm-run-all test:esm compile:def coverage check-coverage",
"test:esm": "mocha \"./lib_esm/test/**/*spec.js\" --require esm",
Expand All @@ -58,7 +58,6 @@
"---------- BUILD STEPS --------": "",
"clean": "shx rm -rf coverage dev lib",
"clean:esm": "shx rm -rf lib_esm",
"lint": "tslint --project tsconfig.json",
"compile": "tsc && node ./scripts/fix-coverage-report.js",
"compile:esm": "tsc --project tsconfig.esm.json",
"compile:watch": "tsc -w",
Expand Down Expand Up @@ -99,7 +98,6 @@
"sinon": "^9.0.0",
"sinon-chai": "^3.0.0",
"source-map-support": "0.5.19",
"tslint": "^6.0.0",
"typedoc": "^0.20.28",
"typescript": "4.2.2",
"vuepress": "^1.4.1",
Expand Down
5 changes: 2 additions & 3 deletions packages/chevrotain/scripts/update-api-docs.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const _ = require("lodash")
const fs = require("fs-extra")
const path = require("path")

pkgPath = path.join(__dirname, "../package.json")
const pkgPath = path.join(__dirname, "../package.json")
const pkg = fs.readJsonSync(pkgPath)

console.log("updating api docs re-direct")
Expand All @@ -15,7 +14,7 @@ const newVersionApiDocsDir = path.join(
)

try {
stats = fs.lstatSync(newVersionApiDocsDir)
const stats = fs.lstatSync(newVersionApiDocsDir)

if (stats.isDirectory()) {
console.error("docs directory for " + noDotsVersion + " already exists")
Expand Down
4 changes: 2 additions & 2 deletions packages/chevrotain/src/generate/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ return new ${options.name}(tokenVocabulary, config)

export function genClass(options: { name: string; rules: Rule[] }): string {
// TODO: how to pass the token vocabulary? Constructor? other?
let result = `
const result = `
function ${options.name}(tokenVocabulary, config) {
// invoke super constructor
// No support for embedded actions currently, so we can 'hardcode'
Expand All @@ -85,7 +85,7 @@ ${options.name}.prototype.constructor = ${options.name}
}

export function genAllRules(rules: Rule[]): string {
let rulesText = map(rules, (currRule) => {
const rulesText = map(rules, (currRule) => {
return genRule(currRule, 1)
})

Expand Down
4 changes: 2 additions & 2 deletions packages/chevrotain/src/lang/lang_extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const NAME = "name"
export function functionName(func: TokenType): string {
// Engines that support Function.prototype.name OR the nth (n>1) time after
// the name has been computed in the following else block.
let existingNameProp = (<any>func).name
const existingNameProp = (<any>func).name
/* istanbul ignore else - too many hacks for IE/old versions of node.js here*/
if (existingNameProp) {
return existingNameProp
Expand All @@ -28,7 +28,7 @@ export function functionName(func: TokenType): string {
* @returns {boolean} - has the property been successfully defined
*/
export function defineNameProp(obj, nameValue): boolean {
let namePropDescriptor = Object.getOwnPropertyDescriptor(obj, NAME)
const namePropDescriptor = Object.getOwnPropertyDescriptor(obj, NAME)
/* istanbul ignore else -> will only run in old versions of node.js */
if (isUndefined(namePropDescriptor) || namePropDescriptor.configurable) {
Object.defineProperty(obj, NAME, {
Expand Down
2 changes: 1 addition & 1 deletion packages/chevrotain/src/parse/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// TODO: can this be removed? where is it used?
export let IN = "_~IN~_"
export const IN = "_~IN~_"
Loading

0 comments on commit efbc5da

Please sign in to comment.