Skip to content

Commit

Permalink
updates for eslint strict type check (#1635)
Browse files Browse the repository at this point in the history
* Update helper file to allow to run task package ci even when no tags are available

* Revert "Update helper file to allow to run task package ci even when no tags are available"

This reverts commit c8b8212.

* Update eslint to ignore some rules for test related files and folders and fix other eslint issues

* Remove use of require statements
  • Loading branch information
audgirka authored Nov 4, 2024
1 parent 376807f commit f24fc8e
Show file tree
Hide file tree
Showing 21 changed files with 66 additions and 186 deletions.
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,13 @@ repos:
language: system
verbose: true # do not remove, as this allows warnings to be displayed on GHA
args:
# default format is not vscode friendly
- --no-warn-ignored
- --color
- --format=gha
- --format=unix
- --fix
# - --max-warnings
# - "0"
pass_filenames: false
files: \.m?[jt]sx?$ # *.js, *.jsx, *.ts and *.tsx
types: [file]

Expand Down
21 changes: 20 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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 pluginChaiFriendly from "eslint-plugin-chai-friendly";
import globals from "globals";
import path from "path";
import { fileURLToPath } from "url";
Expand All @@ -15,7 +16,14 @@ const __dirname = path.dirname(__filename); // get the name of the directory

export default tseslint.config(
{
ignores: ["**/out/", ".vscode-test/*", ".yarn/*", "media/*", "site/*", "commitlint.config.js"],
ignores: [
"**/out/",
".vscode-test/*",
".yarn/*",
"media/*",
"site/*",
"commitlint.config.js",
],
},
{
extends: [
Expand Down Expand Up @@ -63,6 +71,7 @@ export default tseslint.config(
"@typescript-eslint/no-confusing-void-expression": "off",
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-require-imports": "off",
"@typescript-eslint/require-await": "off",
"@typescript-eslint/restrict-plus-operands": "off",
"@typescript-eslint/no-dynamic-delete": "off",
Expand All @@ -89,4 +98,14 @@ export default tseslint.config(
// "@typescript-eslint/no-unsafe-return": "error",
},
},
{
plugins: { "chai-friendly": pluginChaiFriendly },
files: ["**/test/**/*.{js,ts,tsx}"],
rules: {
"no-unused-expressions": "off",
"@typescript-eslint/no-unused-expressions": "off",
"@typescript-eslint/no-require-imports": "off",
"chai-friendly/no-unused-expressions": "error",
},
},
);
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,7 @@
"eslint-config-prettier": "^9.1.0",
"eslint-formatter-gha": "^1.5.1",
"eslint-formatter-unix": "^8.40.0",
"eslint-plugin-chai-friendly": "^1.0.1",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-tsdoc": "^0.3.0",
"find-process": "^1.4.7",
Expand All @@ -976,7 +977,7 @@
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"typescript": "^5.6.3",
"typescript-eslint": "^7.18.0",
"typescript-eslint": "^8.12.2",
"vscode-extension-tester": "^8.3.0",
"warnings-to-errors-webpack-plugin": "^2.3.0",
"webpack": "^5.96.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export class ExecutionEnvironment {
child_process.execSync(`command -v ${ce}`, {
encoding: "utf-8",
});
} catch (error) {
} catch {
this.connection.console.info(`Container engine '${ce}' not found`);
continue;
}
Expand Down Expand Up @@ -384,7 +384,7 @@ export class ExecutionEnvironment {
{ shell: false },
);
containerNameExist = result.toString() !== "";
} catch (error) {
} catch {
containerNameExist = false;
}
return containerNameExist;
Expand Down
2 changes: 1 addition & 1 deletion packages/ansible-language-server/src/utils/docsParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export class LazyModuleDocumentation implements IModuleMetadata {
if (m.groups.name === DOCUMENTATION) {
// determine documentation start/end lines for definition provider
let startLine =
contents.substr(0, m.index).match(/\n/g)?.length || 0;
contents.substring(0, m.index).match(/\n/g)?.length || 0;
startLine += m.groups.pre.match(/\n/g)?.length || 0;
const endLine =
startLine + (m.groups.doc.match(/\n/g)?.length || 0);
Expand Down
2 changes: 1 addition & 1 deletion packages/ansible-language-server/src/utils/imagePuller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class ImagePuller {
encoding: "utf-8",
});
return true;
} catch (error) {
} catch {
this.connection.console.log(
`'${this._containerImage}' image inspection failed, image assumed to be corrupted or missing`,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/ansible-language-server/src/utils/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ export function isCursorInsideJinjaBrackets(

try {
nodeObject = node.toJSON();
} catch (error) {
} catch {
// return early if invalid yaml syntax
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ansible-language-server/test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function logWrapper(
};
}

interface CustomConsole extends Console {}
type CustomConsole = Console;
const customConsole: CustomConsole = Object.create(console);

customConsole.info = logWrapper(console.info as LogFunction, chalk.blue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function getAnsibleTestInfo() {
const ansibleInfo: ansibleMetaDataEntryType = {};
ansibleInfo["core version"] = ".";
ansibleInfo["location"] = "/ansible";
// eslint-disable-next-line chai-friendly/no-unused-expressions
(ansibleInfo["config file path"] = path.resolve(
__dirname,
"..",
Expand Down
2 changes: 1 addition & 1 deletion src/features/lightspeed/explorerWebviewViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class LightspeedExplorerWebviewViewProvider
if (document !== undefined && document.languageId === "ansible") {
try {
return isPlaybook(document.getText());
} catch (error) {
} catch {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/features/lightspeed/lightspeedUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ export class LightspeedUser {
markdownUserInfo = await this.getUserInfoFromMarkdown(
session.accessToken,
);
} catch (error) {
} catch {
markdownUserInfo = "";
}
this._markdownUserDetails = markdownUserInfo;
Expand Down
2 changes: 1 addition & 1 deletion src/features/lightspeed/playbookExplanation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function getObjectKeys(content: string): string[] {
if (typeof lastObject === "object") {
return Object.keys(lastObject);
}
} catch (error) {
} catch {
return [];
}
return [];
Expand Down
4 changes: 2 additions & 2 deletions src/features/lightspeed/playbookGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function contentMatch(generationId: string, playbook: string) {

async function sendActionEvent(
action: PlaybookGenerationActionType,
toPage?: number | undefined,
toPage?: number,
) {
if (currentPanel && wizardId) {
const fromPage = currentPage;
Expand Down Expand Up @@ -206,7 +206,7 @@ export async function showPlaybookGenerationPage(extensionUri: vscode.Uri) {
try {
syntaxHighlighter =
await require(/* webpackIgnore: true */ "../../syntaxHighlighter/src/syntaxHighlighter");
} catch (error) {
} catch {
syntaxHighlighter =
await require(/* webpackIgnore: true */ "../../../../syntaxHighlighter/src/syntaxHighlighter");
}
Expand Down
4 changes: 2 additions & 2 deletions src/features/lightspeed/roleGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function contentMatch(generationId: string, playbook: string) {

async function sendActionEvent(
action: PlaybookGenerationActionType,
toPage?: number | undefined,
toPage?: number,
) {
if (currentPanel && wizardId) {
const fromPage = currentPage;
Expand Down Expand Up @@ -208,7 +208,7 @@ export async function showRoleGenerationPage(extensionUri: vscode.Uri) {
try {
syntaxHighlighter =
await require(/* webpackIgnore: true */ "../../syntaxHighlighter/src/syntaxHighlighter");
} catch (error) {
} catch {
syntaxHighlighter =
await require(/* webpackIgnore: true */ "../../../../syntaxHighlighter/src/syntaxHighlighter");
}
Expand Down
2 changes: 1 addition & 1 deletion src/features/utils/applyFileInspectionForKeywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function applyFileInspectionForKeywords(
);
}
}
} catch (err) {
} catch {
console.error("Error loading yaml file");
}
}
4 changes: 2 additions & 2 deletions src/features/utils/syntaxHighlighter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getHighlighterCore, HighlighterCore } from "@shikijs/core";
import { getSingletonHighlighterCore, HighlighterCore } from "@shikijs/core";
import darkPlus from "shiki/themes/dark-plus.mjs";
import lightPlus from "shiki/themes/light-plus.mjs";
import { default as yamlLang } from "shiki/langs/yaml.mjs";
Expand All @@ -8,7 +8,7 @@ let highlighter: HighlighterCore;

export async function codeToHtml(code: string, theme: string, lang: string) {
if (!highlighter) {
highlighter = await getHighlighterCore({
highlighter = await getSingletonHighlighterCore({
themes: [darkPlus, lightPlus],
langs: [yamlLang],
loadWasm: getWasm,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/executionEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function getContainerEngine(containerEngine: string): string {
child_process.execSync(`which ${ce}`, {
encoding: "utf-8",
});
} catch (error) {
} catch {
continue;
}
engine = ce;
Expand Down
3 changes: 1 addition & 2 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import * as path from "path";
import Mocha from "mocha";
import { glob } from "glob";
import { MochaOptions } from "vscode-extension-tester";
import NYC from "nyc";

function setupCoverage() {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const NYC = require("nyc");
const nyc = new NYC({
cwd: path.join(__dirname, "..", "..", ".."),
reporter: ["text", "html", "lcov"],
Expand Down
1 change: 1 addition & 0 deletions test/lib/nyc.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module "nyc";
2 changes: 1 addition & 1 deletion test/ui-test/uiTestHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function getModalDialogAndMessage(details = false): Promise<{
if (message !== undefined) {
return { dialog, message };
}
} catch (error) {
} catch {
await sleep(1000);
}
}
Expand Down
Loading

0 comments on commit f24fc8e

Please sign in to comment.