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

Commit 00c0406

Browse files
Merge pull request #3 from UziTech/tests
Add tests
2 parents 1009db8 + 9e1d0a3 commit 00c0406

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1613
-74
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spec/fixtures

.github/ISSUE_TEMPLATE.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Issue Type
2+
<!-- Can be "Bug", "Feature Request", "Question", etc.-->
3+
4+
5+
## Issue Description
6+
<!-- Describe what happened, what you think should have happened, and any other relevant details -->
7+
8+
9+
## Bug Checklist
10+
- [ ] Restart Atom
11+
- [ ] Verify the `eslint` CLI gives the proper result, while `linter-eslint-node` does not
12+
- [ ] Paste the output of the `Linter Eslint Node: Debug` command from the Command Palette below
13+
14+
```
15+
Linter Eslint Node: Debug output here
16+
```

.github/renovate.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"schedule": ["every weekend"],
3+
"labels": ["dependencies"],
4+
"separateMajorMinor": "false",
5+
"packageRules": [
6+
{
7+
"matchDepTypes": ["devDependencies"],
8+
"matchUpdateTypes": ["major", "minor", "patch", "pin", "digest", "lockFileMaintenance", "rollback", "bump"],
9+
"groupName": "devDependencies",
10+
"semanticCommitType": "chore",
11+
"automerge": true
12+
},
13+
{
14+
"matchDepTypes": ["dependencies"],
15+
"matchUpdateTypes": ["major", "minor", "patch", "pin", "digest", "lockFileMaintenance", "rollback", "bump"],
16+
"groupName": "dependencies",
17+
"semanticCommitType": "fix"
18+
}
19+
]
20+
}

.github/workflows/CI.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: CI
2+
on:
3+
- pull_request
4+
- push
5+
6+
jobs:
7+
Test:
8+
name: ${{ matrix.os }} - Atom ${{ matrix.atom_channel }} - node ${{ matrix.node_version }}
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
os: [ubuntu-latest, macos-latest, windows-latest]
14+
atom_channel: [stable, beta]
15+
node_version: ['lts/*']
16+
include:
17+
- os: ubuntu-latest
18+
atom_channel: stable
19+
node_version: '*'
20+
steps:
21+
- uses: actions/checkout@v2
22+
- uses: UziTech/action-setup-atom@v2
23+
with:
24+
version: ${{ matrix.atom_channel }}
25+
- uses: actions/setup-node@v3
26+
with:
27+
node-version: ${{ matrix.node_version }}
28+
- name: Install dependencies
29+
run: |
30+
apm install
31+
# ./node_modules/.bin/atom-package-deps .
32+
33+
- name: Run tests 👩🏾‍💻
34+
run: npm run test
35+
36+
Lint:
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v2
40+
with:
41+
fetch-depth: 0
42+
43+
- name: Install dependencies
44+
run: npm install
45+
46+
- name: Lint ✨
47+
run: npm run test.lint
48+
49+
CommitLint:
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@v2
53+
with:
54+
fetch-depth: 0
55+
- name: Commit lint ✨
56+
uses: wagoid/commitlint-github-action@v4
57+
58+
# Release:
59+
# needs: [Test, CommitLint, Lint]
60+
# if: github.ref == 'refs/heads/master' &&
61+
# github.event.repository.fork == false
62+
# runs-on: ubuntu-latest
63+
# steps:
64+
# - uses: actions/checkout@v2
65+
# - uses: UziTech/action-setup-atom@v1
66+
# - uses: actions/setup-node@v3
67+
# with:
68+
# node-version: "lts/*"
69+
# - name: NPM install
70+
# run: npm install
71+
# - name: Release 🎉
72+
# uses: cycjimmy/semantic-release-action@v2
73+
# with:
74+
# extends: @semantic-release/apm-config
75+
# env:
76+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77+
# ATOM_ACCESS_TOKEN: ${{ secrets.ATOM_ACCESS_TOKEN }}

lib/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const Config = {
99
subscriptions: null,
1010
initialized: false,
1111
handlers: [],
12+
overrides: {},
1213

1314
initialize () {
1415
if (this.initialized) { return; }

lib/main.js

Lines changed: 49 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,14 @@ import NodePathTester from './node-path-tester';
1111
import JobManager from './job-manager';
1212
import * as helpers from './helpers';
1313

14-
const IDLE_CALLBACKS = new Set();
15-
16-
const makeIdleCallback = work => {
17-
let callbackId;
18-
const callback = () => {
19-
IDLE_CALLBACKS.delete(callbackId);
20-
work();
21-
};
22-
callbackId = window.requestIdleCallback(callback);
23-
IDLE_CALLBACKS.add(callbackId);
24-
};
25-
26-
const scheduleIdleTasks = () => {
27-
const linterEslintInstallPeerPackages = () => {
28-
require('atom-package-deps').install('linter-eslint-node');
29-
};
30-
31-
if (!atom.inSpecMode()) {
32-
makeIdleCallback(linterEslintInstallPeerPackages);
33-
}
34-
};
35-
36-
const SCOPES = atom.config.get('linter-eslint-node.scopes');
37-
38-
const EMBEDDED_SCOPE = 'source.js.embedded.html';
39-
4014
const BUTTON_SETTINGS = {
4115
text: 'Settings',
4216
onDidClick () {
4317
atom.workspace.open(`atom://config/packages/linter-eslint-node`);
4418
}
4519
};
4620

47-
48-
if (atom.config.get('linter-eslint-node.lintHtmlFiles')) {
49-
if (!SCOPES.includes(EMBEDDED_SCOPE)) {
50-
SCOPES.push(EMBEDDED_SCOPE);
51-
}
52-
} else {
53-
if (SCOPES.includes(EMBEDDED_SCOPE)) {
54-
SCOPES.splice(
55-
SCOPES.indexOf(EMBEDDED_SCOPE),
56-
1
57-
);
58-
}
59-
}
21+
const EMBEDDED_SCOPE = 'source.js.embedded.html';
6022

6123
const RECENTLY_SAVED = new Set();
6224
function hasRecentlySaved (path) {
@@ -65,8 +27,20 @@ function hasRecentlySaved (path) {
6527
setTimeout(() => RECENTLY_SAVED.delete(path), 100);
6628
}
6729

68-
class LinterESLintNode {
69-
constructor () {
30+
export default {
31+
32+
shouldAutoFix (textEditor) {
33+
if (textEditor.isModified()) { return false; }
34+
if (!Config.get('autofix.fixOnSave')) { return false; }
35+
if (!helpers.hasValidScope(textEditor, this.scopes)) { return false; }
36+
return true;
37+
},
38+
39+
isLegacyPackagePresent () {
40+
return ('linter-eslint' in atom.packages.activePackages);
41+
},
42+
43+
async activate () {
7044
Config.initialize();
7145
this.workerPath = Path.join(__dirname, 'worker.js');
7246
NodePathTester.test(Config.get('nodeBin'));
@@ -79,21 +53,23 @@ class LinterESLintNode {
7953
incompatibleVersion: false,
8054
invalidNodeBin: false
8155
};
82-
}
8356

84-
shouldAutoFix (textEditor) {
85-
if (textEditor.isModified()) { return false; }
86-
if (!Config.get('autofix.fixOnSave')) { return false; }
87-
if (!helpers.hasValidScope(textEditor, SCOPES)) { return false; }
88-
return true;
89-
}
57+
this.subscriptions = new CompositeDisposable();
9058

91-
isLegacyPackagePresent () {
92-
return ('linter-eslint' in atom.packages.activePackages);
93-
}
59+
this.scopes = atom.config.get('linter-eslint-node.scopes');
9460

95-
async activate () {
96-
this.subscriptions = new CompositeDisposable();
61+
if (atom.config.get('linter-eslint-node.lintHtmlFiles')) {
62+
if (!this.scopes.includes(EMBEDDED_SCOPE)) {
63+
this.scopes.push(EMBEDDED_SCOPE);
64+
}
65+
} else {
66+
if (this.scopes.includes(EMBEDDED_SCOPE)) {
67+
this.scopes.splice(
68+
this.scopes.indexOf(EMBEDDED_SCOPE),
69+
1
70+
);
71+
}
72+
}
9773

9874
this.subscriptions.add(
9975
atom.workspace.observeTextEditors(
@@ -127,21 +103,21 @@ class LinterESLintNode {
127103
}
128104

129105
if (config.scopes !== prevConfig.scopes) {
130-
SCOPES.splice(0, SCOPES.length);
131-
SCOPES.push(...config.scopes);
106+
this.scopes.splice(0, this.scopes.length);
107+
this.scopes.push(...config.scopes);
132108
if (config.lintHtmlFiles) {
133-
SCOPES.push(EMBEDDED_SCOPE);
109+
this.scopes.push(EMBEDDED_SCOPE);
134110
}
135111
}
136112

137113
if (config.lintHtmlFiles !== prevConfig.lintHtmlFiles) {
138114
if (config.lintHtmlFiles) {
139-
if (!SCOPES.includes(EMBEDDED_SCOPE)) {
140-
SCOPES.push(EMBEDDED_SCOPE);
115+
if (!this.scopes.includes(EMBEDDED_SCOPE)) {
116+
this.scopes.push(EMBEDDED_SCOPE);
141117
}
142118
} else {
143-
if (SCOPES.includes(EMBEDDED_SCOPE)) {
144-
SCOPES.splice(SCOPES.indexOf(EMBEDDED_SCOPE), 1);
119+
if (this.scopes.includes(EMBEDDED_SCOPE)) {
120+
this.scopes.splice(this.scopes.indexOf(EMBEDDED_SCOPE), 1);
145121
}
146122
}
147123
}
@@ -186,14 +162,16 @@ class LinterESLintNode {
186162
})
187163
);
188164

189-
scheduleIdleTasks();
190-
}
165+
if (!atom.inSpecMode()) {
166+
await require('atom-package-deps').install('linter-eslint-node');
167+
}
168+
},
191169

192170
async deactivate () {
193171
this.subscriptions.dispose();
194172
this.jobManager.dispose();
195173
Config.dispose();
196-
}
174+
},
197175

198176
notifyAboutInvalidNodeBin () {
199177
if (this.notified.invalidNodeBin) { return; }
@@ -207,7 +185,7 @@ class LinterESLintNode {
207185
}
208186
);
209187
this.notified.invalidNodeBin = true;
210-
}
188+
},
211189

212190
// We need to tell the worker to clear its cache when
213191
// - any .eslintignore file is changed;
@@ -217,7 +195,7 @@ class LinterESLintNode {
217195
clearESLintCache () {
218196
console.warn('Telling the worker to clear its cache!');
219197
this.jobManager.send({ type: 'clear-cache' });
220-
}
198+
},
221199

222200
// Show a bunch of stuff to the user that can help them figure out why the
223201
// package isn't behaving the way they think it ought to, or else give them
@@ -331,7 +309,7 @@ class LinterESLintNode {
331309
dismissable: true
332310
}
333311
);
334-
}
312+
},
335313

336314
// Here we're operating entirely outside the purview of the `linter` package.
337315
// This method is called either automatically, via `fixOnSave`; or manually,
@@ -386,7 +364,7 @@ class LinterESLintNode {
386364
this.handleError(err);
387365
return;
388366
}
389-
}
367+
},
390368

391369
handleError (err) {
392370
console.debug('handleError:', err);
@@ -451,15 +429,15 @@ class LinterESLintNode {
451429
}
452430
);
453431
}
454-
}
432+
},
455433

456434
provideLinter () {
457435
console.log('provideLinter nodeBin:', Config.get('nodeBin'));
458436
return {
459437
name: 'ESLint (Node)',
460438
scope: 'file',
461439
lintsOnChange: true,
462-
grammarScopes: SCOPES,
440+
grammarScopes: this.scopes,
463441
lint: async (textEditor) => {
464442
console.warn('linting', textEditor);
465443
if (!atom.workspace.isTextEditor(textEditor)) {
@@ -545,8 +523,5 @@ class LinterESLintNode {
545523
}
546524
}
547525
};
548-
}
549-
}
550-
551-
552-
export default new LinterESLintNode();
526+
},
527+
};

0 commit comments

Comments
 (0)