Skip to content

Commit

Permalink
Upgrade to eslint 9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Apr 12, 2024
1 parent 0449ea8 commit 2550212
Show file tree
Hide file tree
Showing 30 changed files with 293 additions and 272 deletions.
28 changes: 0 additions & 28 deletions .eslintrc.yml

This file was deleted.

12 changes: 7 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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 Down Expand Up @@ -80,7 +80,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 @@ -154,7 +154,7 @@ repos:
- id: commitlint
stages: [commit-msg]
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v9.0.0-rc.0
rev: v9.0.0
hooks:
- id: eslint
args:
Expand All @@ -165,14 +165,16 @@ repos:
- --max-warnings
- "0"
additional_dependencies:
- "@eslint/js@>=9.0.0"
- "@typescript-eslint/eslint-plugin"
- "@typescript-eslint/parser"
- eslint
- eslint@9.0.0
- eslint-config-prettier
- eslint-formatter-unix
- eslint-plugin-prettier
- eslint-plugin-tsdoc
- prettier
- typescript
- typescript-eslint
files: \.[jt]sx?$ # *.js, *.jsx, *.ts and *.tsx
files: \.m?[jt]sx?$ # *.js, *.jsx, *.ts and *.tsx
types: [file]
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"Containerfile": "Dockerfile"
},
"editor.formatOnSave": true,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
Expand Down
58 changes: 58 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// @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"],
// temporary skips during eslint 9 upgrade
"no-case-declarations": 0,
"no-constant-condition": 0,
"no-control-regex": 0,
"no-prototype-builtins": 0,
"tsdoc/syntax": "warn",
},
},
);
11 changes: 7 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,21 @@
"@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-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 +793,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
4 changes: 2 additions & 2 deletions packages/ansible-language-server/src/services/ansibleLint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ 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: () => {},
done: () => {},
};

progressTracker.begin("ansible-lint", undefined, "Processing files...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ 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: () => {},
done: () => {},
};

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
6 changes: 2 additions & 4 deletions src/features/ansibleTox/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ export class AnsibleToxController {
}

const splittedPath = uri.path.split("/");
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion

const fileName = splittedPath.pop()!;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion

const parentFolderName = splittedPath.pop()!;

const file = this.controller.createTestItem(uri.toString(), fileName, uri);
Expand Down Expand Up @@ -185,7 +185,6 @@ export class AnsibleToxController {
const queue: vscode.TestItem[] = [...(request.include || [])];

while (queue.length > 0 && !token.isCancellationRequested) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const test = queue.pop()!;

if (request.exclude?.includes(test)) {
Expand All @@ -194,7 +193,6 @@ export class AnsibleToxController {

const start = Date.now();
try {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const cwd = vscode.workspace.getWorkspaceFolder(test.uri!)?.uri.path;
runTox(
[test.label.split("->")[0].trim()],
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 @@ export class LightSpeedAPI {
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
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 @@ export async function inlineSuggestionHideHandler(userAction?: UserAction) {
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
}
case UserAction.IGNORED: {
console.log("[inline-suggestions] User ignored the inline suggestion.");
break;
}
default: {
console.log(
Expand Down
8 changes: 4 additions & 4 deletions src/features/lightspeed/lightSpeedOAuthProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable tsdoc/syntax */

import {
authentication,
AuthenticationProvider,
Expand Down Expand Up @@ -109,7 +109,7 @@ export class LightSpeedAuthenticationProvider

/**
* Get the existing sessions
* @param scopes
* @param scopes - Scopes
* @returns
*/
public async getSessions(): Promise<readonly LightspeedAuthSession[]> {
Expand All @@ -124,7 +124,7 @@ export class LightSpeedAuthenticationProvider

/**
* Create a new auth session
* @param scopes
* @param scopes - Scopes
* @returns
*/
public async createSession(scopes: string[]): Promise<LightspeedAuthSession> {
Expand Down Expand Up @@ -205,7 +205,7 @@ export class LightSpeedAuthenticationProvider

/**
* Remove an existing session
* @param sessionId
* @param sessionId - Session ID
*/
public async removeSession(sessionId: string): Promise<void> {
const allSessions = await this.context.secrets.get(SESSIONS_SECRET_KEY);
Expand Down
1 change: 0 additions & 1 deletion src/features/lightspeed/utils/feedbackView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export function setWebviewMessageListener(
webview: Webview,
disposables: Disposable[] = [],
) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
webview.onDidReceiveMessage(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(message: any) => {
Expand Down
6 changes: 3 additions & 3 deletions src/features/lightspeed/utils/promiseHandlers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable tsdoc/syntax */

import { Disposable, Event, EventEmitter } from "vscode";

export interface PromiseAdapter<T, U> {
Expand All @@ -23,8 +23,8 @@ const passthrough = (value: any, resolve: (value?: any) => void) =>
*
* The default adapter is the passthrough function `(value, resolve) => resolve(value)`.
*
* @param event the event
* @param adapter controls resolution of the returned promise
* @param event - the event
* @param adapter - controls resolution of the returned promise
* @returns a promise that resolves or rejects as specified by the adapter
*/
export function promiseFromEvent<T, U>(
Expand Down
Loading

0 comments on commit 2550212

Please sign in to comment.