Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
priyamsahoo committed Oct 1, 2022
1 parent cce2a5d commit c433849
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 96 deletions.
16 changes: 9 additions & 7 deletions src/providers/validationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function doValidate(
validationManager: ValidationManager,
quick = true,
context?: WorkspaceFolderContext,
connection?: Connection
connection?: Connection,
): Promise<Map<string, Diagnostic[]>> {
let diagnosticsByFile;
if (quick || !context) {
Expand Down Expand Up @@ -55,7 +55,7 @@ export async function doValidate(
? "ansible-lint"
: settings.validation.lint.path;
const lintAvailability = await commandRunner.getExecutablePath(
lintExecutable
lintExecutable,
);
console.debug("Path for lint: ", lintAvailability);

Expand All @@ -64,7 +64,7 @@ export async function doValidate(
diagnosticsByFile = await context.ansibleLint.doValidate(textDocument);
} else {
connection?.window.showErrorMessage(
"Ansible-lint is not available. Kindly check the path or disable validation using ansible-lint"
"Ansible-lint is not available. Kindly check the path or disable validation using ansible-lint",
);
}
}
Expand All @@ -76,7 +76,7 @@ export async function doValidate(
if (isPlaybook(textDocument)) {
console.debug("playbook file");
diagnosticsByFile = await context.ansiblePlaybook.doValidate(
textDocument
textDocument,
);
} else {
console.debug("non-playbook file");
Expand Down Expand Up @@ -116,10 +116,12 @@ export function getYamlValidation(textDocument: TextDocument): Diagnostic[] {
const start = textDocument.positionAt(
errorRange.origStart !== undefined
? errorRange.origStart
: errorRange.start
: errorRange.start,
);
const end = textDocument.positionAt(
errorRange.origEnd !== undefined ? errorRange.origEnd : errorRange.end
errorRange.origEnd !== undefined
? errorRange.origEnd
: errorRange.end,
);
range = Range.create(start, end);

Expand Down Expand Up @@ -166,7 +168,7 @@ export function getYamlValidation(textDocument: TextDocument): Diagnostic[] {
start: range.end,
end: range.end,
}),
"the scope of this error ends here"
"the scope of this error ends here",
),
];
// collapse the range
Expand Down
36 changes: 18 additions & 18 deletions src/services/ansibleLint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class AnsibleLint {
* reported in other files.
*/
public async doValidate(
textDocument: TextDocument
textDocument: TextDocument,
): Promise<Map<string, Diagnostic[]>> {
let diagnostics: Map<string, Diagnostic[]> = new Map();

Expand All @@ -60,13 +60,13 @@ export class AnsibleLint {

// Determine linter config file
let ansibleLintConfigPath = linterArguments.match(
/(?:^|\s)-c\s*(?<sep>[\s'"])(?<conf>.+?)(?:\k<sep>|$)/
/(?:^|\s)-c\s*(?<sep>[\s'"])(?<conf>.+?)(?:\k<sep>|$)/,
)?.groups?.conf;
if (!ansibleLintConfigPath) {
// Config file not provided in arguments -> search for one mimicking the
// way ansible-lint looks for it, going up the directory structure
const ansibleLintConfigFile = await this.findAnsibleLintConfigFile(
textDocument.uri
textDocument.uri,
);
if (ansibleLintConfigFile) {
ansibleLintConfigPath = URI.parse(ansibleLintConfigFile).path;
Expand All @@ -88,15 +88,15 @@ export class AnsibleLint {

const ansibleLintConfigPromise = this.getAnsibleLintConfig(
workingDirectory,
ansibleLintConfigPath
ansibleLintConfigPath,
);

progressTracker.begin("ansible-lint", undefined, "Processing files...");

const commandRunner = new CommandRunner(
this.connection,
this.context,
settings
settings,
);

try {
Expand All @@ -105,13 +105,13 @@ export class AnsibleLint {
"ansible-lint",
`${linterArguments} "${docPath}"`,
workingDirectory,
mountPaths
mountPaths,
);

diagnostics = this.processReport(
result.stdout,
await ansibleLintConfigPromise,
workingDirectory
workingDirectory,
);

if (result.stderr) {
Expand All @@ -129,7 +129,7 @@ export class AnsibleLint {
diagnostics = this.processReport(
execError.stdout,
await ansibleLintConfigPromise,
workingDirectory
workingDirectory,
);
} else {
if (execError.stderr) {
Expand All @@ -142,7 +142,7 @@ export class AnsibleLint {
}
} else {
const exceptionString = `Exception in AnsibleLint service: ${JSON.stringify(
error
error,
)}`;

progressTracker.done();
Expand All @@ -159,12 +159,12 @@ export class AnsibleLint {
private processReport(
result: string,
ansibleLintConfig: IAnsibleLintConfig | undefined,
workingDirectory: string
workingDirectory: string,
): Map<string, Diagnostic[]> {
const diagnostics: Map<string, Diagnostic[]> = new Map();
if (!result) {
this.connection.console.warn(
"Standard output from ansible-lint is suspiciously empty."
"Standard output from ansible-lint is suspiciously empty.",
);
return diagnostics;
}
Expand Down Expand Up @@ -199,7 +199,7 @@ export class AnsibleLint {
let severity: DiagnosticSeverity = DiagnosticSeverity.Error;
if (ansibleLintConfig) {
const lintRuleName = (item.check_name as string).match(
/\[(?<name>[a-z\-]+)\].*/
/\[(?<name>[a-z\-]+)\].*/,
)?.groups?.name;

if (
Expand Down Expand Up @@ -240,7 +240,7 @@ export class AnsibleLint {
} catch (error) {
this.connection.window.showErrorMessage(
"Could not parse ansible-lint output. Please check your ansible-lint installation & configuration." +
" More info in `Ansible Server` output."
" More info in `Ansible Server` output.",
);
let message: string;
if (error instanceof Error) {
Expand All @@ -250,14 +250,14 @@ export class AnsibleLint {
}
this.connection.console.error(
`Exception while parsing ansible-lint output: ${message}` +
`\nTried to parse the following:\n${result}`
`\nTried to parse the following:\n${result}`,
);
}
return diagnostics;
}

public handleWatchedDocumentChange(
params: DidChangeWatchedFilesParams
params: DidChangeWatchedFilesParams,
): void {
for (const fileEvent of params.changes) {
// remove from cache on any change
Expand All @@ -267,7 +267,7 @@ export class AnsibleLint {

private async getAnsibleLintConfig(
workingDirectory: string,
configPath: string | undefined
configPath: string | undefined,
): Promise<IAnsibleLintConfig | undefined> {
if (configPath) {
const absConfigPath = path.resolve(workingDirectory, configPath);
Expand All @@ -281,7 +281,7 @@ export class AnsibleLint {
}

private async readAnsibleLintConfig(
configPath: string
configPath: string,
): Promise<IAnsibleLintConfig> {
const config = {
warnList: new Set<string>(),
Expand Down Expand Up @@ -310,7 +310,7 @@ export class AnsibleLint {
}

private async findAnsibleLintConfigFile(
uri: string
uri: string,
): Promise<string | undefined> {
// find configuration path
let configPath;
Expand Down
4 changes: 2 additions & 2 deletions src/services/settingsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class SettingsManager {

// Structure the settings similar to the ExtensionSettings interface for usage in the code
private defaultSettings: ExtensionSettings = this._settingsAdjustment(
_.cloneDeep(this.defaultSettingsWithDescription)
_.cloneDeep(this.defaultSettingsWithDescription),
);

public globalSettings: ExtensionSettings = this.defaultSettings;
Expand Down Expand Up @@ -174,7 +174,7 @@ export class SettingsManager {
}

public async handleConfigurationChanged(
params: DidChangeConfigurationParams
params: DidChangeConfigurationParams,
): Promise<void> {
if (this.clientSupportsConfigRequests) {
// find configuration change handlers to fire
Expand Down
2 changes: 1 addition & 1 deletion src/utils/execPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ExtensionSettings } from "../interfaces/extensionSettings";
*/
export function getAnsibleCommandExecPath(
name: string,
settings: ExtensionSettings
settings: ExtensionSettings,
): string {
return name === "ansible-lint"
? settings.validation.lint.path
Expand Down
Loading

0 comments on commit c433849

Please sign in to comment.