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

Commit

Permalink
Merge pull request #410 from AtomLinter/arcanemagus/builtins
Browse files Browse the repository at this point in the history
Add support for builtins
  • Loading branch information
Arcanemagus authored Apr 25, 2017
2 parents 570dced + 8986e0e commit 4103736
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 45 deletions.
24 changes: 6 additions & 18 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,51 +82,36 @@ export default {
atom.config.observe('linter-flake8.disableTimeout', (value) => {
this.disableTimeout = value;
}),
);
this.subscriptions.add(
atom.config.observe('linter-flake8.projectConfigFile', (value) => {
this.projectConfigFile = value;
}),
);
this.subscriptions.add(
atom.config.observe('linter-flake8.maxLineLength', (value) => {
this.maxLineLength = value;
}),
);
this.subscriptions.add(
atom.config.observe('linter-flake8.ignoreErrorCodes', (value) => {
this.ignoreErrorCodes = value;
}),
);
this.subscriptions.add(
atom.config.observe('linter-flake8.maxComplexity', (value) => {
this.maxComplexity = value;
}),
);
this.subscriptions.add(
atom.config.observe('linter-flake8.selectErrors', (value) => {
this.selectErrors = value;
}),
);
this.subscriptions.add(
atom.config.observe('linter-flake8.hangClosing', (value) => {
this.hangClosing = value;
}),
);
this.subscriptions.add(
atom.config.observe('linter-flake8.executablePath', (value) => {
this.executablePath = value;
}),
);
this.subscriptions.add(
atom.config.observe('linter-flake8.pycodestyleErrorsToWarnings', (value) => {
this.pycodestyleErrorsToWarnings = value;
}),
);
this.subscriptions.add(
atom.config.observe('linter-flake8.flakeErrors', (value) => {
this.flakeErrors = value;
}),
atom.config.observe('linter-flake8.builtins', (value) => {
this.builtins = value;
}),
);
},

Expand Down Expand Up @@ -168,6 +153,9 @@ export default {
if (this.selectErrors.length) {
parameters.push('--select', this.selectErrors.join(','));
}
if (this.builtins.length) {
parameters.push('--builtins', this.builtins.join(','));
}
}

parameters.push('-');
Expand Down
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@
"description": "Convert Flake \"F\" messages to linter errors",
"type": "boolean",
"default": false
},
"builtins": {
"type": "array",
"default": [],
"items": {
"type": "string"
},
"description": "Define additional built in variables, in a comma separated list."
}
},
"dependencies": {
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/builtins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo = bar
foobar = foo_bar
107 changes: 80 additions & 27 deletions spec/linter-flake8-spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use babel';

import * as path from 'path';
import { join } from 'path';

const fixturePath = path.join(__dirname, 'fixtures');
const goodPath = path.join(fixturePath, 'good.py');
const badPath = path.join(fixturePath, 'bad.py');
const errwarnPath = path.join(fixturePath, 'errwarn.py');
const fixturePath = join(__dirname, 'fixtures');
const goodPath = join(fixturePath, 'good.py');
const badPath = join(fixturePath, 'bad.py');
const errwarnPath = join(fixturePath, 'errwarn.py');
const builtinsPath = join(fixturePath, 'builtins.py');

describe('The flake8 provider for Linter', () => {
const lint = require('../lib/main.js').provideLinter().lint;
Expand Down Expand Up @@ -149,53 +150,53 @@ describe('The flake8 provider for Linter', () => {

it('finds executable relative to project', () => {
atom.config.set('linter-flake8.executablePath',
path.join('$PROJECT', 'flake8'),
join('$PROJECT', 'flake8'),
);
waitsForPromise(() =>
lint(editor).then(() =>
expect(execParams.pop()[0]).toBe(path.join(fixturePath, 'flake8')),
expect(execParams.pop()[0]).toBe(join(fixturePath, 'flake8')),
),
);
});

it('finds executable relative to projects', () => {
const paths = [
path.join('$project', 'null'),
path.join('$pRoJeCt', 'flake1'),
path.join('$PrOjEcT', 'flake2'),
path.join('$PROJECT', 'flake8'),
join('$project', 'null'),
join('$pRoJeCt', 'flake1'),
join('$PrOjEcT', 'flake2'),
join('$PROJECT', 'flake8'),
].join(';');
atom.config.set('linter-flake8.executablePath', paths);
waitsForPromise(() =>
lint(editor).then(() =>
expect(execParams.pop()[0]).toBe(path.join(fixturePath, 'flake8')),
expect(execParams.pop()[0]).toBe(join(fixturePath, 'flake8')),
),
);
});

it('finds executable using project name', () => {
atom.config.set('linter-flake8.executablePath',
path.join('$PROJECT_NAME', 'flake8'),
join('$PROJECT_NAME', 'flake8'),
);
waitsForPromise(() =>
lint(editor).then(() =>
expect(execParams.pop()[0]).toBe(path.join('fixtures', 'flake8')),
expect(execParams.pop()[0]).toBe(join('fixtures', 'flake8')),
),
);
});

it('finds executable using project names', () => {
const paths = [
path.join('$project_name', 'null'),
path.join('$pRoJeCt_NaMe', 'flake1'),
path.join('$PrOjEcT_nAmE', 'flake2'),
path.join('$PROJECT_NAME', 'flake8'),
join('$project_name', 'null'),
join('$pRoJeCt_NaMe', 'flake1'),
join('$PrOjEcT_nAmE', 'flake2'),
join('$PROJECT_NAME', 'flake8'),
].join(';');
const correct = [
path.join('fixtures', 'null'),
path.join('fixtures', 'flake1'),
path.join('fixtures', 'flake2'),
path.join('fixtures', 'flake8'),
join('fixtures', 'null'),
join('fixtures', 'flake1'),
join('fixtures', 'flake2'),
join('fixtures', 'flake8'),
].join(';');
atom.config.set('linter-flake8.executablePath', paths);
waitsForPromise(() =>
Expand All @@ -207,26 +208,78 @@ describe('The flake8 provider for Linter', () => {

it('normalizes executable path', () => {
atom.config.set('linter-flake8.executablePath',
path.join(fixturePath, '..', 'fixtures', 'flake8'),
join(fixturePath, '..', 'fixtures', 'flake8'),
);
waitsForPromise(() =>
lint(editor).then(() =>
expect(execParams.pop()[0]).toBe(path.join(fixturePath, 'flake8')),
expect(execParams.pop()[0]).toBe(join(fixturePath, 'flake8')),
),
);
});

it('finds backup executable', () => {
const flakeNotFound = path.join('$PROJECT', 'flake8_notfound');
const flakeBackup = path.join(fixturePath, 'flake8_backup');
const flakeNotFound = join('$PROJECT', 'flake8_notfound');
const flakeBackup = join(fixturePath, 'flake8_backup');
atom.config.set('linter-flake8.executablePath',
`${flakeNotFound};${flakeBackup}`,
);
waitsForPromise(() =>
lint(editor).then(() =>
expect(execParams.pop()[0]).toBe(path.join(fixturePath, 'flake8_backup')),
expect(execParams.pop()[0]).toBe(join(fixturePath, 'flake8_backup')),
),
);
});
});

describe('works with defining builtins', () => {
let editor;

beforeEach(() => {
waitsForPromise(() =>
atom.workspace.open(builtinsPath).then((openEditor) => { editor = openEditor; }),
);
});

it('shows all warnings when the setting is blank', () => {
waitsForPromise(() =>
lint(editor).then((messages) => {
expect(messages.length).toBe(2);

expect(messages[0].type).toBe('Warning');
expect(messages[0].html).not.toBeDefined();
expect(messages[0].text).toBe('F821 — undefined name \'bar\'');
expect(messages[0].filePath).toBe(builtinsPath);
expect(messages[0].range).toEqual([[0, 6], [0, 9]]);

expect(messages[1].type).toBe('Warning');
expect(messages[1].html).not.toBeDefined();
expect(messages[1].text).toBe('F821 — undefined name \'foo_bar\'');
expect(messages[1].filePath).toBe(builtinsPath);
expect(messages[1].range).toEqual([[1, 9], [1, 16]]);
}),
);
});

it('works with a single builtin', () => {
atom.config.set('linter-flake8.builtins', ['bar']);
waitsForPromise(() =>
lint(editor).then((messages) => {
expect(messages.length).toBe(1);

expect(messages[0].type).toBe('Warning');
expect(messages[0].html).not.toBeDefined();
expect(messages[0].text).toBe('F821 — undefined name \'foo_bar\'');
expect(messages[0].filePath).toBe(builtinsPath);
expect(messages[0].range).toEqual([[1, 9], [1, 16]]);
}),
);
});

it('works with multiple builtins', () => {
atom.config.set('linter-flake8.builtins', ['bar', 'foo_bar']);
waitsForPromise(() =>
lint(editor).then(messages => expect(messages.length).toBe(0)),
);
});
});
});

0 comments on commit 4103736

Please sign in to comment.