Skip to content

Commit

Permalink
Tooling update (#1043)
Browse files Browse the repository at this point in the history
* remove TSLint from recommendations, instead suggest ESLint

* add prettier to workspace recommendations, since project assumes prettier usage

* auto-formatter (hopefully prettier) is making changes to src/*.ts; they seem reasonable...

* trying to silence eslint warnings for unused vars; but its not working...

* fix eslint warnings related to null in utils.ts

* silenced no-explicit-any related warnings; also, unused vars related warning are also being correctly suppressed

---------

Co-authored-by: fendor <[email protected]>
  • Loading branch information
bzm3r and fendor authored Feb 19, 2024
1 parent 5769ee2 commit a2677f7
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 133 deletions.
26 changes: 13 additions & 13 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"overrides": [],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"plugins": ["@typescript-eslint"],
"rules": {
"semi": [
"error",
"always"
]
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{
"varsIgnorePattern": "^_",
"argsIgnorePattern": "^_"
}
],
"@typescript-eslint/no-explicit-any": "off",
"semi": ["error", "always"]
}
}
}
7 changes: 5 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"recommendations": ["ms-vscode.vscode-typescript-tslint-plugin"]
}
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
".cabal"
]
},

{
"id": "literate haskell",
"aliases": [
Expand Down Expand Up @@ -1153,8 +1152,8 @@
"@types/node": "^20.11.17",
"@types/vscode": "^1.82.0",
"@types/which": "^3.0.3",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@vscode/test-electron": "^2.3.8",
"eslint": "^8.56.0",
"eslint-webpack-plugin": "^4.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Uri } from 'vscode';

export class HlsError extends Error {}
export class HlsError extends Error { }

export class MissingToolError extends HlsError {
public readonly tool: string;
Expand Down
36 changes: 18 additions & 18 deletions src/hlsBinaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,13 @@ export async function findHaskellLanguageServer(
const stackInstalled = latestStack ? await toolInstalled(context, logger, 'stack', latestStack) : undefined;
const ghcInstalled = executableExists('ghc')
? new InstalledTool(
'ghc',
await callAsync(`ghc${exeExt}`, ['--numeric-version'], logger, undefined, undefined, false)
)
'ghc',
await callAsync(`ghc${exeExt}`, ['--numeric-version'], logger, undefined, undefined, false)
)
: // if recGHC is null, that means user disabled automatic handling,
recGHC !== null
? await toolInstalled(context, logger, 'ghc', recGHC)
: undefined;
? await toolInstalled(context, logger, 'ghc', recGHC)
: undefined;
const toInstall: InstalledTool[] = [hlsInstalled, cabalInstalled, stackInstalled, ghcInstalled].filter(
(tool) => tool && !tool.installed
) as InstalledTool[];
Expand Down Expand Up @@ -459,12 +459,12 @@ async function getLatestProjectHLS(
// get project GHC version, but fallback to system ghc if necessary.
const projectGhc = toolchainBindir
? await getProjectGHCVersion(toolchainBindir, workingDir, logger).catch(async (e) => {
logger.error(`${e}`);
window.showWarningMessage(
`I had trouble figuring out the exact GHC version for the project. Falling back to using 'ghc${exeExt}'.`
);
return await callAsync(`ghc${exeExt}`, ['--numeric-version'], logger, undefined, undefined, false);
})
logger.error(`${e}`);
window.showWarningMessage(
`I had trouble figuring out the exact GHC version for the project. Falling back to using 'ghc${exeExt}'.`
);
return await callAsync(`ghc${exeExt}`, ['--numeric-version'], logger, undefined, undefined, false);
})
: await callAsync(`ghc${exeExt}`, ['--numeric-version'], logger, undefined, undefined, false);

// first we get supported GHC versions from available HLS bindists (whether installed or not)
Expand Down Expand Up @@ -858,13 +858,13 @@ async function getReleaseMetadata(
: undefined;
const opts: https.RequestOptions = releasesUrl
? {
host: releasesUrl.host,
path: releasesUrl.pathname,
}
host: releasesUrl.host,
path: releasesUrl.pathname,
}
: {
host: 'raw.githubusercontent.com',
path: '/haskell/ghcup-metadata/master/hls-metadata-0.0.1.json',
};
host: 'raw.githubusercontent.com',
path: '/haskell/ghcup-metadata/master/hls-metadata-0.0.1.json',
};

const offlineCache = path.join(storagePath, 'ghcupReleases.cache.json');

Expand Down Expand Up @@ -915,7 +915,7 @@ async function getReleaseMetadata(

window.showWarningMessage(
"Couldn't get the latest haskell-language-server releases from GitHub, used local cache instead: " +
githubError.message
githubError.message
);
return cachedInfoParsed;
} catch (fileError) {
Expand Down
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ export function resolvePATHPlaceHolders(path: string) {
return path
.replace('${HOME}', os.homedir)
.replace('${home}', os.homedir)
.replace('$PATH', process.env.PATH!)
.replace('${PATH}', process.env.PATH!);
.replace('$PATH', process.env.PATH ?? '$PATH')
.replace('${PATH}', process.env.PATH ?? '${PATH}');
}

// also honours serverEnvironment.PATH
Expand All @@ -207,7 +207,7 @@ export async function addPathToProcessPath(extraPath: string): Promise<string> {
const serverEnvironment: IEnvVars = (await workspace.getConfiguration('haskell').get('serverEnvironment')) || {};
const path: string[] = serverEnvironment.PATH
? serverEnvironment.PATH.split(pathSep).map((p) => resolvePATHPlaceHolders(p))
: process.env.PATH!.split(pathSep);
: process.env.PATH?.split(pathSep) ?? [];
path.unshift(extraPath);
return path.join(pathSep);
}
Expand Down
Loading

0 comments on commit a2677f7

Please sign in to comment.