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

Ignore extensions #37

Merged
merged 10 commits into from
Sep 5, 2015
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ You can configure linter-ruby by editing ~/.atom/config.cson (choose Open Your C
```
'linter-ruby':
'rubyExecutablePath': null #ruby path. run 'which ruby' to find the path.
'ignoredExtensions': 'erb,md' #ignored extensions, ERB and markdown files by default.
```

## Contributing
Expand Down
45 changes: 31 additions & 14 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export default {
rubyExecutablePath: {
type: "string",
default: "ruby"
},
ignoredExtensions: {
type: "string",
Copy link
Contributor

Choose a reason for hiding this comment

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

ignoredExtensions: {
  type: 'array',
  default: ['erb', 'md'],
  items: {
    type: 'string'
  }
}

default: "erb,md"
}
},

Expand Down Expand Up @@ -38,23 +42,36 @@ export default {
lintOnFly: true,
lint: (activeEditor) => {
const command = atom.config.get("linter-ruby.rubyExecutablePath");
const ignored = atom.config.get("linter-ruby.ignoredExtensions");
const filePath = activeEditor.getPath();
return helpers.exec(command, ['-wc'], {stdin: activeEditor.getText(), stream: 'stderr'}).then(output => {
var toReturn = [];
output.split(/\r?\n/).forEach(function (line) {
const matches = regex.exec(line);
if (matches === null) {
return;
}
toReturn.push({
range: helpers.rangeFromLineNumber(activeEditor, Number.parseInt((matches[1] - 1))),
type: matches[2],
text: matches[3],
filePath: filePath
var ignore = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

const fileExtension = Path.extname(filePath).substr(1)
documentation for Path.extname
Also, you should do const Path = require('path') where the helpers are defined.


ignored.split(",").forEach(function (extension) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You won't have to split if you make it an array. Also you should do for...of instead of foreach, You won't have to use the ignore variable then, you can just return from the loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Awesome, thanks again 👍

if (filePath.split(".").pop() === extension.trim()) {
ignore = true;
};
});

if (ignore) {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about if (ignore) return []
You don't need an else block as you are returning from the first one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that’s much better, thanks!

return;
} else {
return helpers.exec(command, ['-wc'], {stdin: activeEditor.getText(), stream: 'stderr'}).then(output => {
var toReturn = [];
output.split(/\r?\n/).forEach(function (line) {
const matches = regex.exec(line);
if (matches === null) {
return;
}
toReturn.push({
range: helpers.rangeFromLineNumber(activeEditor, Number.parseInt((matches[1] - 1))),
type: matches[2],
text: matches[3],
filePath: filePath
});
});
return toReturn;
});
return toReturn;
});
}
}
};
}
Expand Down