From 1449bd1aca4fa83db4154670ae87a56e9fe6dd4b Mon Sep 17 00:00:00 2001 From: adanski Date: Wed, 6 Dec 2023 22:49:03 +0100 Subject: [PATCH] Upgrade linter, provide consistent cross-platform env --- .eslintrc.yaml | 1 + .gitattributes | 2 ++ .prettierrc.yaml | 2 ++ docs/package.json | 8 ++--- package.json | 17 +++++----- packages/textcomplete-codemirror/package.json | 8 ++--- .../textcomplete-contenteditable/package.json | 8 ++--- packages/textcomplete-core/package.json | 8 ++--- packages/textcomplete-core/src/Dropdown.ts | 8 ++--- packages/textcomplete-core/src/Editor.ts | 33 ++++++++++--------- packages/textcomplete-textarea/package.json | 8 ++--- packages/textcomplete-utils/package.json | 11 +++---- 12 files changed, 59 insertions(+), 55 deletions(-) create mode 100644 .prettierrc.yaml diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 8905f3d4..9e030321 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -16,3 +16,4 @@ rules: - ignoreRestSiblings: true argsIgnorePattern: '^_' '@typescript-eslint/no-explicit-any': 'error' + 'prettier/prettier': 'error' diff --git a/.gitattributes b/.gitattributes index 66763d68..5762a256 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,4 @@ packages/jquery-textcomplete/dist/* linguist-vendored packages/jquery-textcomplete/src/vendor/* linguist-vendored + +* text=auto eol=lf diff --git a/.prettierrc.yaml b/.prettierrc.yaml new file mode 100644 index 00000000..7d20c9a1 --- /dev/null +++ b/.prettierrc.yaml @@ -0,0 +1,2 @@ +trailingComma: 'es5' +semi: false diff --git a/docs/package.json b/docs/package.json index cc1a2c31..63549e16 100644 --- a/docs/package.json +++ b/docs/package.json @@ -3,11 +3,11 @@ "private": true, "version": "0.1.12", "scripts": { - "build": "rm -fr dist .cache && parcel build index.pug --public-url /textcomplete", - "format:eslint": "eslint --fix '**/*.ts' '**/*.tsx'", - "format:prettier": "prettier --write '**/*.ts' '**/*.tsx'", + "build": "rimraf dist .cache && parcel build index.pug --public-url /textcomplete", + "format:eslint": "eslint --fix **/*.ts **/*.tsx", + "format:prettier": "prettier --write **/*.ts **/*.tsx", "format": "run-s format:eslint format:prettier", - "lint": "eslint '**/*.ts' '**/*.tsx'", + "lint": "eslint **/*.ts **/*.tsx", "start": "parcel index.pug" }, "dependencies": { diff --git a/package.json b/package.json index 47f8357b..71ea925f 100644 --- a/package.json +++ b/package.json @@ -17,19 +17,18 @@ }, "devDependencies": { "@types/jest": "^29.5.10", - "@typescript-eslint/eslint-plugin": "^4.17.0", - "@typescript-eslint/parser": "^4.17.0", - "eslint": "^7.21.0", - "eslint-config-prettier": "^8.1.0", - "eslint-plugin-prettier": "^4.0.0", + "@typescript-eslint/eslint-plugin": "^6.13.2", + "@typescript-eslint/parser": "^6.13.2", + "eslint": "^8.55.0", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-prettier": "^5.0.1", "jest": "^29.7.0", + "jest-environment-jsdom": "~29.7.0", "lerna": "^8.0.0", + "rimraf": "^5.0.5", "npm-run-all": "^4.1.5", - "prettier": "^2.0.5", + "prettier": "^3.1.0", "ts-jest": "^29.1.1", "typescript": "^5.3.2" - }, - "prettier": { - "semi": false } } diff --git a/packages/textcomplete-codemirror/package.json b/packages/textcomplete-codemirror/package.json index 0e222fc2..529c63aa 100644 --- a/packages/textcomplete-codemirror/package.json +++ b/packages/textcomplete-codemirror/package.json @@ -9,11 +9,11 @@ "author": "Yuku Takahashi", "license": "MIT", "scripts": { - "build": "rm -fr dist && tsc", - "format:eslint": "eslint --fix 'src/**/*.ts'", - "format:prettier": "prettier --write 'src/**/*.ts'", + "build": "rimraf dist && tsc", + "format:eslint": "eslint --fix src/**/*.ts", + "format:prettier": "prettier --write src/**/*.ts", "format": "run-s format:eslint format:prettier", - "lint": "eslint 'src/**/*.ts'" + "lint": "eslint src/**/*.ts" }, "devDependencies": { "@textcomplete/core": "^0.1.12", diff --git a/packages/textcomplete-contenteditable/package.json b/packages/textcomplete-contenteditable/package.json index 9deac4ac..3f554d25 100644 --- a/packages/textcomplete-contenteditable/package.json +++ b/packages/textcomplete-contenteditable/package.json @@ -9,11 +9,11 @@ "author": "Yuku Takahashi", "license": "MIT", "scripts": { - "build": "rm -fr dist && tsc", - "format:eslint": "eslint --fix 'src/**/*.ts'", - "format:prettier": "prettier --write 'src/**/*.ts'", + "build": "rimraf dist && tsc", + "format:eslint": "eslint --fix src/**/*.ts", + "format:prettier": "prettier --write src/**/*.ts", "format": "run-s format:eslint format:prettier", - "lint": "eslint 'src/**/*.ts'" + "lint": "eslint src/**/*.ts" }, "dependencies": { "@textcomplete/utils": "^0.1.12" diff --git a/packages/textcomplete-core/package.json b/packages/textcomplete-core/package.json index d079e710..cd07d623 100644 --- a/packages/textcomplete-core/package.json +++ b/packages/textcomplete-core/package.json @@ -9,11 +9,11 @@ "author": "Yuku Takahashi", "license": "MIT", "scripts": { - "build": "rm -fr dist && tsc", - "format:eslint": "eslint --fix 'src/**/*.ts'", - "format:prettier": "prettier --write 'src/**/*.ts'", + "build": "rimraf dist && tsc", + "format:eslint": "eslint --fix src/**/*.ts", + "format:prettier": "prettier --write src/**/*.ts", "format": "run-s format:eslint format:prettier", - "lint": "eslint 'src/**/*.ts'", + "lint": "eslint src/**/*.ts", "test": "jest" }, "dependencies": { diff --git a/packages/textcomplete-core/src/Dropdown.ts b/packages/textcomplete-core/src/Dropdown.ts index b6714c2c..24c28c3d 100644 --- a/packages/textcomplete-core/src/Dropdown.ts +++ b/packages/textcomplete-core/src/Dropdown.ts @@ -248,8 +248,8 @@ export class Dropdown extends EventEmitter { return this.activeIndex < this.items.length - 1 ? this.activeIndex + 1 : this.option.rotate - ? 0 - : null + ? 0 + : null } private getPrevActiveIndex(): number | null { @@ -257,8 +257,8 @@ export class Dropdown extends EventEmitter { return this.activeIndex !== 0 ? this.activeIndex - 1 : this.option.rotate - ? this.items.length - 1 - : null + ? this.items.length - 1 + : null } private renderItems(): this { diff --git a/packages/textcomplete-core/src/Editor.ts b/packages/textcomplete-core/src/Editor.ts index a08fcb9e..67872957 100644 --- a/packages/textcomplete-core/src/Editor.ts +++ b/packages/textcomplete-core/src/Editor.ts @@ -109,20 +109,23 @@ export abstract class Editor extends EventEmitter { * @see {@link Textarea} for live example. */ protected getCode(e: KeyboardEvent): KeyCode { - return e.keyCode === 9 // tab - ? "ENTER" - : e.keyCode === 13 // enter - ? "ENTER" - : e.keyCode === 27 // esc - ? "ESC" - : e.keyCode === 38 // up - ? "UP" - : e.keyCode === 40 // down - ? "DOWN" - : e.keyCode === 78 && e.ctrlKey // ctrl-n - ? "DOWN" - : e.keyCode === 80 && e.ctrlKey // ctrl-p - ? "UP" - : "OTHER" + switch (e.keyCode) { + case 9: // tab + case 13: // enter + return "ENTER" + case 27: // esc + return "ESC" + case 38: // up + return "UP" + case 40: // down + return "DOWN" + case 78: // ctrl-n + if (e.ctrlKey) return "DOWN" + break + case 80: // ctrl-p + if (e.ctrlKey) return "UP" + break + } + return "OTHER" } } diff --git a/packages/textcomplete-textarea/package.json b/packages/textcomplete-textarea/package.json index 407d5e87..813ecdc6 100644 --- a/packages/textcomplete-textarea/package.json +++ b/packages/textcomplete-textarea/package.json @@ -9,11 +9,11 @@ "author": "Yuku Takahashi", "license": "MIT", "scripts": { - "build": "rm -fr dist && tsc", - "format:eslint": "eslint --fix 'src/**/*.ts'", - "format:prettier": "prettier --write 'src/**/*.ts'", + "build": "rimraf dist && tsc", + "format:eslint": "eslint --fix src/**/*.ts", + "format:prettier": "prettier --write src/**/*.ts", "format": "run-s format:eslint format:prettier", - "lint": "eslint 'src/**/*.ts'" + "lint": "eslint src/**/*.ts" }, "dependencies": { "@textcomplete/utils": "^0.1.12", diff --git a/packages/textcomplete-utils/package.json b/packages/textcomplete-utils/package.json index ca4b14e9..6421941b 100644 --- a/packages/textcomplete-utils/package.json +++ b/packages/textcomplete-utils/package.json @@ -9,11 +9,11 @@ "author": "Yuku Takahashi", "license": "MIT", "scripts": { - "build": "rm -fr dist && tsc", - "format:eslint": "eslint --fix 'src/**/*.ts'", - "format:prettier": "prettier --write 'src/**/*.ts'", + "build": "rimraf dist && tsc", + "format:eslint": "eslint --fix src/**/*.ts", + "format:prettier": "prettier --write src/**/*.ts", "format": "run-s format:eslint format:prettier", - "lint": "eslint 'src/**/*.ts'" + "lint": "eslint src/**/*.ts" }, "devDependencies": { "@textcomplete/core": "^0.1.12", @@ -27,8 +27,5 @@ }, "publishConfig": { "access": "public" - }, - "prettier": { - "semi": false } }