Skip to content

Commit

Permalink
Add enable setting for ability to do project-specific disabling (#26)
Browse files Browse the repository at this point in the history
* Add `enable` setting for ability to do project-specific disabling

* Add spec for `enable` setting

* Make the spec more thorough

* Fix default (again)
  • Loading branch information
savetheclocktower authored Aug 12, 2024
1 parent bb5137b commit 333301d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ export default {
this.clearESLintCache();
}

if (config.enabled) {
this.wake();
}

if (config.scopes !== prevConfig.scopes) {
this.scopes.splice(0, this.scopes.length);
this.scopes.push(...config.scopes);
Expand Down Expand Up @@ -242,6 +246,7 @@ export default {
},

notifyAboutTimeout (timeoutError, editor = null) {
if (this.inactive) return;
let forASpecificEditor = '';
if (editor && editor.getPath) {
forASpecificEditor = `for \`${editor.getPath()}\``;
Expand Down Expand Up @@ -401,6 +406,10 @@ export default {
// file in place. Atom notices the file has changed and updates the buffer
// contents.
async fixJob (isSave = false) {
if (!Config.get('enable')) {
this.sleep(`Disabled in config`);
return;
}
const textEditor = atom.workspace.getActiveTextEditor();
if (!textEditor || !atom.workspace.isTextEditor(textEditor)) {
return;
Expand Down Expand Up @@ -452,6 +461,10 @@ export default {
},

handleError (err, type, editor = null) {
if (!Config.get('enable')) {
this.sleep(`Disabled in config`);
return;
}
if (err.name && err.name === 'TimeoutError') {
// An operation timed out. We should tell the user but should not sleep
// the worker, since we have no idea what caused the timeout or if it's
Expand Down Expand Up @@ -572,6 +585,10 @@ export default {
lintsOnChange: true,
grammarScopes: this.scopes,
lint: async (textEditor) => {
if (!Config.get('enable')) {
this.sleep(`Disabled in config`);
return;
}
console.warn('Linting', textEditor);
if (!atom.workspace.isTextEditor(textEditor)) {
return null;
Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
"core:loaded-shell-environment"
],
"configSchema": {
"enable": {
"title": "Enable",
"description": "Whether to enable this package’s behavior. Provided as a way to disable linting for certain projects without having to disable the package.",
"type": "boolean",
"default": true,
"order": 0
},
"scopes": {
"title": "List of scopes to run ESLint on",
"description": "Run `Editor: Log Cursor Scope` to determine the scopes for a file. To lint JavaScript inside HTML files, add `source.js.embedded.html` to this list and be sure that `eslint-plugin-html` is installed and added to your `.eslintrc`.",
Expand Down
21 changes: 21 additions & 0 deletions spec/linter-eslint-node-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ describe('The eslint provider for Linter', () => {

beforeEach(async () => {
atom.config.set('linter-eslint-node.advanced.disableEslintIgnore', true);
atom.config.set('linter-eslint-node.enable', true);

// Activate activation hook
atom.packages.triggerDeferredActivationHooks();
Expand Down Expand Up @@ -263,6 +264,26 @@ describe('The eslint provider for Linter', () => {
expect(messages.length).toBe(1);
rimraf.sync(tempDir);
});

it('will do nothing while "enable" option is `false`, but wake if "enable" is set to `true`', async () => {
atom.config.set('linter-eslint-node.enable', false);
const tempPath = await copyFileToTempDir(
path.join(paths.eslintignoreDir, 'ignored.js')
);
const tempDir = path.dirname(tempPath);
const editor = await atom.workspace.open(tempPath);
atom.config.set('linter-eslint-node.advanced.disableEslintIgnore', false);
await copyFileToDir(path.join(paths.eslintignoreDir, '.eslintrc.yaml'), tempDir);

let messages = await lint(editor);
expect(messages).toBeUndefined();

atom.config.set('linter-eslint-node.enable', true);
messages = await lint(editor);
expect(messages.length).toBe(1);

rimraf.sync(tempDir);
});
});

// These tests fail when the worker runs `lintText`, but pass when it runs
Expand Down

0 comments on commit 333301d

Please sign in to comment.