Skip to content

Commit 17f7025

Browse files
committed
Lint code with ESLint
And fix the errors it picks up after using the AirBnb style guide.
1 parent 659ddac commit 17f7025

File tree

9 files changed

+2021
-25
lines changed

9 files changed

+2021
-25
lines changed

.eslintrc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"env": {
3+
"commonjs": true,
4+
"es2021": true
5+
},
6+
"extends": "airbnb-base",
7+
"overrides": [],
8+
"parserOptions": {
9+
"ecmaVersion": "2022"
10+
},
11+
"rules": {
12+
"quotes": ["error", "double"],
13+
"space-before-function-paren": ["error", "never"],
14+
"arrow-parens": ["error", "as-needed"],
15+
"class-methods-use-this": ["off"],
16+
"comma-dangle": [
17+
"error",
18+
{
19+
"functions": "never",
20+
"arrays": "always-multiline",
21+
"objects": "always-multiline",
22+
"imports": "always-multiline",
23+
"exports": "always-multiline"
24+
}
25+
]
26+
},
27+
"globals": {
28+
"Issue": "readonly",
29+
"IssueCollection": "readonly",
30+
"IssueSeverity": "readonly",
31+
"nova": "readonly",
32+
"NotificationRequest": "readonly",
33+
"Process": "readonly",
34+
"Range": "readonly"
35+
}
36+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.DS_Store
2+
node_modules/

Scripts/Flake8Process.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ class Flake8Process {
99
async process(commandArguments) {
1010
let flake8Path = nova.workspace.config.get("is.flother.Blake.flake8ExecutablePath");
1111
const maxLineLength = nova.workspace.config.get("is.flother.Blake.maxLineLength");
12+
let args = commandArguments;
1213
if (maxLineLength) {
13-
commandArguments = ["--max-line-length", maxLineLength.toString(), ...commandArguments];
14+
args = ["--max-line-length", maxLineLength.toString(), ...args];
1415
}
1516
if (!flake8Path) {
1617
flake8Path = "/usr/bin/env";
17-
commandArguments = ["flake8", ...commandArguments];
18+
args = ["flake8", ...args];
1819
}
1920
return new Process(flake8Path, {
20-
args: commandArguments,
21+
args,
2122
cwd: nova.workspace.path,
2223
shell: true,
2324
stdio: ["ignore", "pipe", "pipe"],
@@ -56,17 +57,18 @@ class Flake8Process {
5657
request.actions = [nova.localize("OK")];
5758
const promise = nova.notifications.add(request);
5859
promise.then(
59-
_ => { },
60+
() => { },
6061
error => {
62+
// eslint-disable-next-line no-console -- Last ditch attempt to put the error somewhere.
6163
console.error(error);
6264
}
6365
);
6466
}
65-
this._onCompleteCallback(this.violations);
67+
this.onCompleteCallback(this.violations);
6668
}
6769

6870
onComplete(callback) {
69-
this._onCompleteCallback = callback;
71+
this.onCompleteCallback = callback;
7072
}
7173
}
7274

Scripts/Formatter.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ class Formatter {
1212
request.actions = [nova.localize("OK")];
1313
const promise = nova.notifications.add(request);
1414
promise.then(
15-
_ => { },
15+
() => { },
1616
error => {
17+
// eslint-disable-next-line no-console -- Last ditch attempt to put the error somewhere.
1718
console.error(error);
1819
}
1920
);
2021
}
2122

2223
format(editor) {
2324
if (editor.document.isEmpty) {
24-
return;
25+
return null;
2526
}
2627

2728
const textRange = new Range(0, editor.document.length);

Scripts/Violation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class Violation {
3232
return {
3333
code: codeMessage[0],
3434
message: data[3],
35-
col: parseInt(data[2]),
36-
row: parseInt(data[1]),
35+
col: parseInt(data[2], 10),
36+
row: parseInt(data[1], 10),
3737
};
3838
}
3939

Scripts/main.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
const Linter = require("./Linter");
22
const Formatter = require("./Formatter");
33

4-
exports.activate = function() {
4+
exports.activate = () => {
55
const linter = new Linter();
66
const formatter = new Formatter();
77

88
nova.workspace.onDidAddTextEditor(editor => {
9-
const document = editor.document;
9+
const { document } = editor;
1010

1111
if (document.syntax !== "python") {
1212
return;
1313
}
1414

1515
linter.lintDocument(document);
1616

17-
editor.onDidSave(_ => linter.lintDocument(document));
18-
document.onDidChangeSyntax(document => linter.lintDocument(document));
19-
editor.onWillSave(editor => {
17+
editor.onDidSave(() => linter.lintDocument(document));
18+
document.onDidChangeSyntax(linter.lintDocument);
19+
editor.onWillSave(ed => {
2020
const formatOnSave = nova.workspace.config.get("is.flother.Blake.formatOnSave");
2121
if (formatOnSave) {
22-
return formatter.format(editor);
22+
return formatter.format(ed);
2323
}
24+
return null;
2425
});
2526

2627
editor.onDidDestroy(destroyedEditor => {
27-
const anotherEditor = nova.workspace.textEditors.find(editor => {
28-
return editor.document.path === destroyedEditor.document.path;
29-
});
28+
const anotherEditor = nova.workspace.textEditors.find(
29+
ed => ed.document.path === destroyedEditor.document.path
30+
);
3031
if (!anotherEditor) {
3132
linter.removeIssues(destroyedEditor.document.uri);
3233
}

0 commit comments

Comments
 (0)