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

Already on GitHub? Sign in to your account

Upgrade to eslint v9 #1223

Merged
merged 1 commit into from
Apr 12, 2024
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
2 changes: 2 additions & 0 deletions .depcheckrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ ignores:
- "@types/vscode-webview" # provides VSCodeAPI
- "@vscode/vsce"
- depcheck
- eslint-formatter-gha
- eslint-formatter-unix
- mochawesome
- mochawesome-report-generator
- ovsx
Expand Down
28 changes: 0 additions & 28 deletions .eslintrc.yml

This file was deleted.

44 changes: 19 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ci:
- yarn-dedupe
- codecov
- depcheck
- eslint
exclude: >
(?x)^(
.config/requirements.in|
Expand All @@ -21,7 +22,7 @@ exclude: >
minimum_pre_commit_version: 2.9.0 # types_or
repos:
- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v8.6.1
rev: v8.7.0
hooks:
- id: cspell
# name: Spell check with cspell
Expand All @@ -48,6 +49,22 @@ repos:
language: system
pass_filenames: false
always_run: true
- id: eslint
name: eslint
entry: npx eslint
language: system
verbose: true # do not remove, as this allows warnings to be displayed on GHA
args:
# default format is not vscode friendly
- --color
- --format=gha
- --format=unix
- --fix
# - --max-warnings
# - "0"
files: \.m?[jt]sx?$ # *.js, *.jsx, *.ts and *.tsx
types: [file]

- id: git-dirty
name: Check if git reports dirty
entry: git diff --exit-code
Expand Down Expand Up @@ -80,7 +97,7 @@ repos:
# entry: npx yarn npm audit

- repo: https://github.com/pre-commit/pre-commit-hooks.git
rev: v4.5.0
rev: v4.6.0
hooks:
- id: end-of-file-fixer
exclude: >
Expand Down Expand Up @@ -153,26 +170,3 @@ repos:
hooks:
- id: commitlint
stages: [commit-msg]
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v9.0.0-rc.0
hooks:
- id: eslint
args:
# default format is not vscode friendly
- --color
- --format=unix
- --fix
- --max-warnings
- "0"
additional_dependencies:
- "@typescript-eslint/eslint-plugin"
- "@typescript-eslint/parser"
- eslint
- eslint-config-prettier
- eslint-plugin-prettier
- eslint-plugin-tsdoc
- prettier
- typescript
- typescript-eslint
files: \.[jt]sx?$ # *.js, *.jsx, *.ts and *.tsx
types: [file]
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
"README.md": "CONTRIBUTING.md, LICENSE, CHANGELOG.md, USAGE_DATA.md",
"Containerfile": "Dockerfile"
},
"editor.codeActionsOnSave": ["source.fixAll.eslint"],
"editor.formatOnSave": true,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
Expand All @@ -32,5 +36,5 @@
},
"redhat.telemetry.enabled": false,
"eslint.useESLintClass": true,
"eslint.packageManager": "yarn"
"eslint.experimental.useFlatConfig": true
}
63 changes: 63 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// @ts-check
// cspell: ignore tseslint
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import tsParser from "@typescript-eslint/parser";
import ts from "@typescript-eslint/eslint-plugin";
import tsdocPlugin from "eslint-plugin-tsdoc";
import prettierRecommendedConfig from "eslint-plugin-prettier/recommended";
import globals from "globals";
import path from "path";
import { fileURLToPath } from "url";

const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
const __dirname = path.dirname(__filename); // get the name of the directory

export default tseslint.config(
{
ignores: ["**/out/", ".yarn/*", "media/*"],
},
{
extends: [
eslint.configs.recommended,
...tseslint.configs.recommended,
prettierRecommendedConfig,
],
files: [
"**/*.{js,ts,tsx}",
"packages/**/*.{js,ts,tsx}",
"test/**/*.{js,ts,tsx}",
],
languageOptions: {
globals: {
...globals.node,
...globals.mocha,
...globals.commonjs,
...globals.es2017,
},
parser: tsParser,
parserOptions: {
project: true,
tsconfigRootDir: __dirname,
},
},
plugins: {
"@typescript-eslint": ts,
tsdoc: tsdocPlugin,
},
rules: {
eqeqeq: ["error", "smart"],
"tsdoc/syntax": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-unused-vars": "error",
// Fix temporary off/warn made during eslint v9 upgrade:
"@typescript-eslint/no-non-null-assertion": "warn",
"no-empty-function": "warn",
"no-case-declarations": "off",
"no-constant-condition": "off",
"no-control-regex": "off",
"no-prototype-builtins": "off",
},
},
);
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@
},
"description": "Ansible language support",
"devDependencies": {
"@eslint/js": "^9.0.0",
"@types/chai": "^4.3.14",
"@types/express": "^4.17.21",
"@types/glob": "^8.1.0",
Expand All @@ -765,20 +766,23 @@
"@types/uuid": "^9.0.8",
"@types/vscode": "^1.85.0",
"@types/vscode-webview": "^1.57.5",
"@typescript-eslint/eslint-plugin": "^7.5.0",
"@typescript-eslint/parser": "^7.5.0",
"@typescript-eslint/eslint-plugin": "^7.6.0",
"@typescript-eslint/parser": "^7.6.0",
"@vscode/test-electron": "^2.3.9",
"@vscode/vsce": "^2.24.0",
"axios": "^1.6.8",
"chai": "^4.4.1",
"copyfiles": "^2.4.1",
"depcheck": "^1.4.7",
"eslint": "^8.57.0",
"eslint": "^9.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-formatter-gha": "^1.4.3",
"eslint-formatter-unix": "^8.40.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-tsdoc": "^0.2.17",
"find-process": "^1.4.7",
"glob": "^10.3.12",
"globals": "^15.0.0",
"lodash": "^4.17.21",
"mocha": "^10.4.0",
"mochawesome": "^7.1.3",
Expand All @@ -791,7 +795,8 @@
"sinon": "^17.0.1",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"typescript": "^5.4.4",
"typescript": "^5.4.5",
"typescript-eslint": "^7.6.0",
"vscode-extension-tester": "^8.0.2",
"warnings-to-errors-webpack-plugin": "^2.3.0",
"webpack": "^5.91.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/ansible-language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"nyc": "^15.1.0",
"rimraf": "^5.0.5",
"ts-node": "^10.9.2",
"typescript": "^5.4.4"
"typescript": "^5.4.5"
},
"scripts": {
"clean": "rimraf out/server && rimraf lib",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ export class AnsibleLint {
const progressTracker = this.useProgressTracker
? await this.connection.window.createWorkDoneProgress()
: {
begin: () => {}, // eslint-disable-line @typescript-eslint/no-empty-function
done: () => {}, // eslint-disable-line @typescript-eslint/no-empty-function
begin: () => {
// do nothing
},
done: () => {
// do nothing
},
};

progressTracker.begin("ansible-lint", undefined, "Processing files...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ export class AnsiblePlaybook {
const progressTracker = this.useProgressTracker
? await this.connection.window.createWorkDoneProgress()
: {
begin: () => {}, // eslint-disable-line @typescript-eslint/no-empty-function
done: () => {}, // eslint-disable-line @typescript-eslint/no-empty-function
begin: () => {
// do nothing
},
done: () => {
// do nothing
},
};

const workingDirectory = URI.parse(this.context.workspaceFolder.uri).path;
Expand Down
2 changes: 1 addition & 1 deletion packages/ansible-language-server/src/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function hasOwnProperty<X, Y extends PropertyKey>(
obj: X,
prop: Y,
): obj is X & Record<Y, unknown> {
return isObject(obj) && obj.hasOwnProperty(prop);
return isObject(obj) && Object.prototype.hasOwnProperty.call(obj, prop);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function testAnsibleSyntaxCheckNoHost(
diagnosticReport: [
{
severity: 1,
// eslint-disable-next-line quotes

message: "the field 'hosts' is required but was not set",
range: {
start: { line: 0, character: 0 } as Position,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,11 @@ const settingsReadmeFileUri = path.join(__dirname, "..", "docs", "settings.md");
// Register a special function for handlebars to deal with comparison of stringed value of false
// Else, normal #if treats it as boolean, even after converting booleans to strings in typescript
Handlebars.registerHelper("ifEqualsFalse", function (arg1, options) {
// eslint-disable-next-line eqeqeq
return arg1.toString() === "false" ? options.fn(this) : options.inverse(this);
});

// Register a special function for handlebars to deal with the checking of "list" as value type of settings
Handlebars.registerHelper("ifValueArray", function (arg1, options) {
// eslint-disable-next-line eqeqeq
return arg1.toString() === "list" ? options.fn(this) : options.inverse(this);
});

Expand Down
8 changes: 4 additions & 4 deletions packages/ansible-language-server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"compilerOptions": {
"alwaysStrict": true,
"declaration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"lib": ["es2016"],
"lib": ["ES2020"],
"module": "commonjs",
"moduleResolution": "node",
"outDir": "./out/server",
"skipLibCheck": true,
"sourceMap": true,
"target": "es6",
"esModuleInterop": true,
"skipLibCheck": true
"target": "ES2020"
},
"exclude": ["node_modules", "out", "vscode-ansible"]
}
1 change: 0 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,6 @@ async function resyncAnsibleInventory(): Promise<void> {
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async function getAuthToken(): Promise<void> {
if (
!(await workspace.getConfiguration("ansible").get("lightspeed.enabled"))
Expand Down
12 changes: 4 additions & 8 deletions src/features/lightspeed/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,10 @@
console.error("Ansible Lightspeed instance is not initialized.");
return;
}
try {
const response = await axiosInstance.get(urlPath, {
timeout: ANSIBLE_LIGHTSPEED_API_TIMEOUT,
});
return response.data;
} catch (error) {
throw error;
}
const response = await axiosInstance.get(urlPath, {
timeout: ANSIBLE_LIGHTSPEED_API_TIMEOUT,
});
return response.data;

Check warning on line 90 in src/features/lightspeed/api.ts

View check run for this annotation

Codecov / codecov/patch

src/features/lightspeed/api.ts#L90

Added line #L90 was not covered by tests
}

public async completionRequest(
Expand Down
4 changes: 3 additions & 1 deletion src/features/lightspeed/feedbackWebviewViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export class LightspeedFeedbackWebviewViewProvider
{
public static readonly viewType = "lightspeed-feedback-webview";

constructor(private readonly _extensionUri: Uri) {}
constructor(private readonly _extensionUri: Uri) {
// do nothing
}

public resolveWebviewView(
webviewView: WebviewView,
Expand Down
2 changes: 2 additions & 0 deletions src/features/lightspeed/inlineSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -876,9 +876,11 @@
switch (action) {
case UserAction.REJECTED: {
console.log("[inline-suggestions] User rejected the inline suggestion.");
break;

Check warning on line 879 in src/features/lightspeed/inlineSuggestions.ts

View check run for this annotation

Codecov / codecov/patch

src/features/lightspeed/inlineSuggestions.ts#L879

Added line #L879 was not covered by tests
ssbarnea marked this conversation as resolved.
Show resolved Hide resolved
}
case UserAction.IGNORED: {
console.log("[inline-suggestions] User ignored the inline suggestion.");
break;
ssbarnea marked this conversation as resolved.
Show resolved Hide resolved
}
default: {
console.log(
Expand Down
Loading