Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
Pass filename to Flake8
Browse files Browse the repository at this point in the history
Pass the filename as the argument "stdin-display-name".
Change the working directory where flask8 is executed to the same directory as the configuration file. This ensures that relative patterns defined in the configuration file work properly.
Add test.

This commit implements #454
  • Loading branch information
lucasdf committed Aug 19, 2017
1 parent 064f774 commit 6c84a01
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,15 @@ export default {
parameters.push('--builtins', this.builtins.join(','));
}
}
parameters.push('--stdin-display-name', filePath);

parameters.push('-');

const execPath = fs.normalize(applySubstitutions(this.executablePath, baseDir));
const forceTimeout = 1000 * 60 * 5; // (ms * s * m) = Five minutes
const options = {
stdin: fileText,
cwd: path.dirname(textEditor.getPath()),
cwd: baseDir,
ignoreExitCode: true,
timeout: forceTimeout,
uniqueKey: `linter-flake8:${filePath}`,
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/with-config-file/bad-ignored.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
asfd
1 change: 1 addition & 0 deletions spec/fixtures/with-config-file/subdir/bad-ignored.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
asfd
2 changes: 2 additions & 0 deletions spec/fixtures/with-config-file/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
exclude = bad-ignored.py, subdir/bad-ignored.py
23 changes: 23 additions & 0 deletions spec/linter-flake8-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import { beforeEach, it } from 'jasmine-fix';
// NOTE: If using fit you must add it to the list above!

const fixturePath = join(__dirname, 'fixtures');
const fixtureWithConfigPath = join(__dirname, 'fixtures', 'with-config-file');
const goodPath = join(fixturePath, 'good.py');
const badPath = join(fixturePath, 'bad.py');
const badIgnoredPath = join(fixtureWithConfigPath, 'bad-ignored.py');
const badSubdirIgnoredPath = join(fixtureWithConfigPath, 'subdir', 'bad-ignored.py');
const errwarnPath = join(fixturePath, 'errwarn.py');
const builtinsPath = join(fixturePath, 'builtins.py');

Expand Down Expand Up @@ -86,6 +89,26 @@ describe('The flake8 provider for Linter', () => {
});
});

describe('use configuration file and', () => {
let editor = null;

beforeEach(async () => {
atom.project.addPath(fixtureWithConfigPath);
editor = await atom.workspace.open(badIgnoredPath);
});

it('ignores file excluded in configuration file', async () => {
const messages = await lint(editor);
expect(messages.length).toBe(0);
});

it('ignores file excluded in configuration file using relative path', async () => {
editor = await atom.workspace.open(badSubdirIgnoredPath);
const messages = await lint(editor);
expect(messages.length).toBe(0);
});
});

it('finds nothing wrong with a valid file', async () => {
const editor = await atom.workspace.open(goodPath);
const messages = await lint(editor);
Expand Down

0 comments on commit 6c84a01

Please sign in to comment.