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

Optionally omit globals warning #10

Merged
merged 7 commits into from
Jan 12, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 11 additions & 7 deletions lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as helpers from 'atom-linter';
import { CompositeDisposable } from 'atom';

const parseRegex = /^(?:line)? \[?(\d+)]?(?:: (.+))?/gm;
const globalRegex = /accessing global/g;
let executablePath;

export default {
Expand Down Expand Up @@ -58,6 +59,7 @@ export default {

const messages = [];
let match = parseRegex.exec(result);
let globalsOmitted = atom.config.get('linter-moonscript.omitGlobalCheck');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please observe this setting like this, there's no need to go through the complexity of determining what it is and what the current value is on every call 😉.

while (match !== null) {
// Convert the line to 0-indexed for Atom
const line = Number.parseInt(match[1], 10) - 1;
Expand All @@ -78,13 +80,15 @@ export default {
});
} else {
// Regular lint warning
messages.push({
type: 'Warning',
severity: 'warning',
filePath,
text: match[2],
range: helpers.rangeFromLineNumber(textEditor, line),
});
if (!globalRegex.test(match[2]) && !globalsOmitted) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be ||.

As it currently stands, if match[2] contains accessing global it will always be ignored. If it doesn't contain accessing global then the globalsOmitted option being false lets it show up, but if somebody enabled it then all messages will be hidden.

messages.push({
type: 'Warning',
severity: 'warning',
filePath,
text: match[2],
range: helpers.rangeFromLineNumber(textEditor, line),
});
}
}

// Grab the next match in the output
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"type": "string",
"default": "moonc",
"description": "Full path to the moonscript compiler."
},
"omitGlobalCheck": {
"type": "boolean",
"default": false,
"description": "Omit \"accessing global\" warning."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"warnings"

}
},
"license": "MIT",
Expand Down