Skip to content

Commit

Permalink
Sync with upstream (#7)
Browse files Browse the repository at this point in the history
* Fix special characters in workspace and file paths (#15)

* Advise yamllint installation and use (#16)

* Fix handling of files with CRLF line endings (#20)

* Mimic linter's config file search algorithm (#22)

Since ansible-lint is executed from the root directory of the workspace
the algorithm that it uses to find configuration for a particular file
is not involved. To compensate, the extension now mimics that behavior,
searching the directory structure, going up from the investigated file.

At the same time, it is still possible to force a particular config file
through arguments provided in the extension settings.

The configuration file that is actually used is now correctly identified
for the purpose of marking configured finding groups as warnings.
  • Loading branch information
tomaciazek authored and priyamsahoo committed Sep 15, 2021
1 parent df868df commit 02713ee
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/providers/validationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ValidationManager } from '../services/validationManager';
import { WorkspaceFolderContext } from '../services/workspaceManager';
import { parseAllDocuments } from '../utils/yaml';
import { libraryChecker } from '../utils/libraryChecker';
import { parseAllDocuments } from '../utils/yaml';

/**
* Validates the given document.
Expand Down
4 changes: 2 additions & 2 deletions src/services/ansibleConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as child_process from 'child_process';
import * as ini from 'ini';
import * as _ from 'lodash';
import * as path from 'path';
import { URI } from 'vscode-uri';
import { URL } from 'url';
import { Connection } from 'vscode-languageserver';
import { withInterpreter } from '../utils/misc';
import { WorkspaceFolderContext } from './workspaceManager';
Expand Down Expand Up @@ -35,7 +35,7 @@ export class AnsibleConfig {

const ansibleConfigResult = child_process.execSync(ansibleConfigCommand, {
encoding: 'utf-8',
cwd: URI.parse(this.context.workspaceFolder.uri).path,
cwd: decodeURI(new URL(this.context.workspaceFolder.uri).pathname),
env: ansibleConfigEnv,
});

Expand Down
16 changes: 10 additions & 6 deletions src/services/ansibleLint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as child_process from 'child_process';
import { ExecException } from 'child_process';
import { promises as fs } from 'fs';
import * as path from 'path';
import { URI } from 'vscode-uri';
import { URL } from 'url';
import { promisify } from 'util';
import {
Connection,
Expand Down Expand Up @@ -53,7 +53,9 @@ export class AnsibleLint {
): Promise<Map<string, Diagnostic[]>> {
let diagnostics: Map<string, Diagnostic[]> = new Map();

const workingDirectory = URI.parse(this.context.workspaceFolder.uri).path;
const workingDirectory = decodeURI(
new URL(this.context.workspaceFolder.uri).pathname
);

const settings = await this.context.documentSettings.get(textDocument.uri);

Expand All @@ -71,13 +73,15 @@ export class AnsibleLint {
textDocument.uri
);
if (ansibleLintConfigFile) {
ansibleLintConfigPath = URI.parse(ansibleLintConfigFile).path;
ansibleLintConfigPath = decodeURI(
new URL(ansibleLintConfigFile).pathname
);
linterArguments = `${linterArguments} -c "${ansibleLintConfigPath}"`;
}
}
linterArguments = `${linterArguments} --offline --nocolor -f codeclimate`;

const docPath = URI.parse(textDocument.uri).path;
const docPath = decodeURI(new URL(textDocument.uri).pathname);
let progressTracker;
if (this.useProgressTracker) {
progressTracker = await this.connection.window.createWorkDoneProgress();
Expand All @@ -98,7 +102,7 @@ export class AnsibleLint {

const [command, env] = withInterpreter(
settings.ansibleLint.path,
`${linterArguments} "${docPath}"`,
`${linterArguments} --offline --nocolor -f codeclimate "${docPath}"`,
settings.python.interpreterPath,
settings.python.activationScript
);
Expand Down Expand Up @@ -217,7 +221,7 @@ export class AnsibleLint {
}
}
const path = `${workingDirectory}/${item.location.path}`;
const locationUri = URI.file(path).toString();
const locationUri = `file://${encodeURI(path)}`;

let fileDiagnostics = diagnostics.get(locationUri);
if (!fileDiagnostics) {
Expand Down

0 comments on commit 02713ee

Please sign in to comment.