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

Rewrite in JS and update #122

Merged
merged 21 commits into from
Aug 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ If you would like to contribute enhancements or fixes, please do the following:
Please note that modications should follow these coding guidelines:

- Indent is 2 spaces.
- Code should pass coffeelint linter.
- Code should pass ESLint linter.
- Vertical whitespace helps readability, don’t be afraid to use it.

Thank you for helping out!
5 changes: 0 additions & 5 deletions coffeelint.json

This file was deleted.

145 changes: 145 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
'use babel';

// eslint-disable-next-line import/no-extraneous-dependencies, import/extensions
import { CompositeDisposable } from 'atom';

// Dependencies
let helpers;
let path;
let fs;

const applySubstitutions = (givenExecPath, projDir) => {
let execPath = givenExecPath;
const projectName = path.basename(projDir);
execPath = execPath.replace(/\$PROJECT_NAME/ig, projectName);
execPath = execPath.replace(/\$PROJECT/ig, projDir);
const paths = execPath.split(';');
const foundPath = paths.find(testPath => fs.existsSync(testPath));
if (foundPath) {
return foundPath;
}
return execPath;
};

const loadDeps = () => {
if (!helpers) {
helpers = require('atom-linter');
}
if (!path) {
path = require('path');
}
if (!fs) {
fs = require('fs-plus');
}
};

module.exports = {
activate() {
this.idleCallbacks = new Set();
let depsCallbackID;
const installLinterJSHintDeps = () => {
this.idleCallbacks.delete(depsCallbackID);
if (!atom.inSpecMode()) {
require('atom-package-deps').install('linter-pycodestyle');
}
loadDeps();
};
depsCallbackID = window.requestIdleCallback(installLinterJSHintDeps);
this.idleCallbacks.add(depsCallbackID);

this.subscriptions = new CompositeDisposable();
this.subscriptions.add(
atom.config.observe('linter-pycodestyle.maxLineLength', (value) => {
this.maxLineLength = value;
}),
atom.config.observe('linter-pycodestyle.ignoreErrorCodes', (value) => {
this.ignoreCodes = value;
}),
atom.config.observe('linter-pycodestyle.convertAllErrorsToWarnings', (value) => {
this.convertAllErrorsToWarnings = value;
}),
atom.config.observe('linter-pycodestyle.executablePath', (value) => {
this.executablePath = value;
}),
atom.config.observe('linter-pycodestyle.forcedConfig', (value) => {
this.forcedConfig = value;
}),
);
},

deactivate() {
this.idleCallbacks.forEach(callbackID => window.cancelIdleCallback(callbackID));
this.idleCallbacks.clear();
this.subscriptions.dispose();
},

provideLinter() {
return {
name: 'pycodestyle',
grammarScopes: ['source.python', 'source.python.django'],
scope: 'file',
lintsOnChange: true,
lint: async (textEditor) => {
const filePath = textEditor.getPath();
const fileContents = textEditor.getText();

let projectPath = atom.project.relativizePath(filePath)[0];
if (projectPath === null) {
// Default project directory to file directory if path cannot be determined
projectPath = path.dirname(filePath);
}

const parameters = [];
if (this.maxLineLength) {
parameters.push(`--max-line-length=${this.maxLineLength}`);
}
if (this.ignoreCodes) {
parameters.push(`--ignore=${this.ignoreCodes.join(',')}`);
}
if (this.forcedConfig) {
const forcedConfigPath = fs.normalize(applySubstitutions(this.forcedConfig, projectPath));
parameters.push(`--config=${forcedConfigPath}`);
}
parameters.push('-');

loadDeps();

const execOpts = {
cwd: projectPath,
env: process.env,
stdin: fileContents,
ignoreExitCode: true,
};

const execPath = fs.normalize(applySubstitutions(this.executablePath, projectPath));

const results = await helpers.exec(execPath, parameters, execOpts);

if (textEditor.getText() !== fileContents) {
// File has changed since the lint was triggered, tell Linter not to update
return null;
}

const toReturn = [];
const regex = /stdin:(\d+):(\d+):(.*)/g;
const severity = this.convertAllErrorsToWarnings ? 'warning' : 'error';

let match = regex.exec(results);
while (match !== null) {
const line = Number.parseInt(match[1], 10) - 1 || 0;
const col = Number.parseInt(match[2], 10) - 1 || 0;
toReturn.push({
severity,
excerpt: match[3].trim(),
location: {
file: filePath,
position: helpers.generateRange(textEditor, line, col),
},
});
match = regex.exec(results);
}
return toReturn;
},
};
},
};
60 changes: 0 additions & 60 deletions lib/main.coffee

This file was deleted.

70 changes: 60 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,61 @@
{
"name": "linter-pycodestyle",
"main": "./lib/main",
"main": "./lib/index",
"version": "2.0.2",
"description": "Linter plugin for pycodestyle",
"repository": "https://github.com/AtomLinter/linter-pycodestyle",
"license": "MIT",
"configSchema": {
"executablePath": {
"type": "string",
"default": "pycodestyle",
"description": "Semicolon separated list of paths to a binary (e.g. `/usr/local/bin/pycodestyle`). Use `$PROJECT` or `$PROJECT_NAME` substitutions for project specific paths e.g. `$PROJECT/.venv/bin/pycodestyle;/usr/bin/pycodestyle`"
},
"maxLineLength": {
"type": "integer",
"default": 0
},
"ignoreErrorCodes": {
"title": "Ignored Error Codes",
"type": "array",
"default": [],
"description": "For a list of code visit http://pycodestyle.readthedocs.org/en/latest/intro.html#error-codes"
},
"convertAllErrorsToWarnings": {
"type": "boolean",
"default": true
},
"forcedConfig": {
"type": "string",
"default": "",
"description": "Forces `pycodestyle` to use this configuration at all times. Supports substituion of `$PROJECT` and `$PROJECT_NAME`."
}
},
"scripts": {
"test": "apm test",
"lint": "coffeelint ."
"lint": "eslint ."
},
"engines": {
"atom": ">0.50.0"
"atom": ">=1.7.0 <2.0.0"
},
"dependencies": {
"atom-linter": "^8.0.0",
"atom-package-deps": "^4.0.1"
"atom-linter": "^10.0.0",
"atom-package-deps": "^4.6.0",
"fs-plus": "^3.0.1"
},
"devDependencies": {
"jasmine-fix": "^1.0.1",
"coffeelint": "^1.9.7"
"eslint": "^4.4.1",
"eslint-config-airbnb-base": "^11.3.1",
"eslint-plugin-import": "^2.7.0",
"jasmine-fix": "^1.0.1"
},
"package-deps": [
"linter"
"linter:2.0.0"
],
"providedServices": {
"linter": {
"versions": {
"1.0.0": "provideLinter"
"2.0.0": "provideLinter"
}
}
},
Expand All @@ -36,5 +65,26 @@
"linter",
"pep8",
"pycodestyle"
]
],
"eslintConfig": {
"extends": "airbnb-base",
"rules": {
"global-require": "off",
"import/no-unresolved": [
"error",
{
"ignore": [
"atom"
]
}
]
},
"globals": {
"atom": true
},
"env": {
"node": true,
"browser": true
}
}
}
6 changes: 6 additions & 0 deletions spec/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
env: {
jasmine: true,
atomtest: true,
}
};
Empty file added spec/fixtures/pycodestyle
Empty file.
Empty file.
Loading