SublimeLinter ESLint: Lint Whole Project/Directory Instead of Individual File - sublimetext3

After an hour+ on Google, I can't believe I haven't found any answers or questions to this. I'm using the SublimeLinter-contrib-eslint package in Sublime Text 3. Is there a way to force SublimeLinter to lint a whole project instead of just one file?
I have a semi-large client-side project with a lot of separate files, and obviously, these files share variables across the window. However, by default, SublimeLinter only lints a single file, so it throws errors that '<variable>' is not defined (no-undef) when another file defines it and '<variable>' is defined but never used (no-unused-vars) when other files use it.
In my .eslintrc, I can set these global variables like this:
"globals": {
"m": true,
"app": true
},
I could also do this in each file, which is arguably good practice anyway:
var m = m || {};
var app = app || {};
But these methods do not fix the unused variable errors.
The best solution I've come up with is to force SublimeLinter to lint the entire directory rather than the individual file. I can't figure out a way to do this though.
I tried turning on the chdir setting in SublimeLinter's user settings:
{
"user": {
...
"linters": {
"eslint": {
"#disable": false,
"args": [],
"excludes": [],
"chdir": "${project}"
}
},
...
}
}
But ^this just sets the $PWD when running eslint, not the arguments passed to eslint.
So is there a way to force SublimeLinter to lint an entire directory (or the whole project)? Is there a better solution to this problem that I haven't thought of? Maybe I'm just spoiled by go fmt.

Related

Trying to ignore flake8 W503 error in Sublime, but edits to user settings do not affect it

I have tried editing my user Sublime Linter settings to:
"linters":
{
"flake8": {
"args": ["--ignore W503"],
},
}
However, this has not gotten rid of the error flags.
First you probably want --extend-ignore and not --ignore
second, your arguments are malformed, you're telling flake8 to ignore the W503 code (note the space at the beginning)
Here's how you could configure sublime to do what you want:
I have tried editing my user Sublime Linter settings to:
"linters":
{
"flake8": {
"args": ["--extend-ignore", "W503"],
},
}
though I'd suggest instead to configure flake8 via its config file:
[flake8]
extend-ignore = W503
note that you shouldn't need that, since W503 is part of the default ignore set
disclaimer: I'm the current flake8 maintainer

Is there a way to ignore test files for eslint-plugin-security?

With a node.js project, I've added eslint-plugin-security and it is giving a lot of warnings for code in my test/spec files (using mochajs). Since the test code won't be running in production, these don't seem as useful as they do in the project's actual code. (A lot of Generic Object Injection Sink warnings )
Is there a way to have the security plugin ignore certain files other than putting /* eslint-disable */ at the top of every spec file?
The best way I found to deal with this case is based on this answer.
You can override parts of your eslint file in a subfolder. In my case I'm disabling problematic rules from a jest plugin inside my e2e tests folder. Example .eslintrc.js in /e2e-tests/ :
module.exports = {
overrides: [
{
files: ["*.spec.js"],
rules: {
"jest/valid-expect": 0
}
}
]
};
There is three way to ignore files or folders:
1. Creating a .eslintignore on your project root folder with the thing you want to ignore:
**/*.js
2. Using eslint cli & the --ignore-path to specify another file where your ignore rules will be located
eslint --ignore-path .jshintignore file.js
3. Using your package.json
{
"name": "mypackage",
"version": "0.0.1",
"eslintConfig": {
"env": {
"browser": true,
"node": true
}
},
"eslintIgnore": ["*.spec.ts", "world.js"]
}
Official Documentation
On my side, I had issue with Intellij IDEA where eslint was checking files in a folder only dedicated to Typescript (+tslint) which was a pain, so I've picked solution 3.

disable jshint for project using Sublime 3

I have a project in which I'm using standard as the default linter, according to sublimeLinter documentation y need to create a .sublime-project file with the following info:
{
"folders":
[
{
"path": "."
}
],
"SublimeLinter":
{
"linters":
{
"jshint": {
"disable": true
}
}
}
}
however this isn't working, I've tried using both disable and #disable, created a .sublimelinterrc file with the same info, also tried with a .sublime-workspacefile, didn't worked, created a .jshintignore... didnt work.
Until now, the only thing that has worked is using this line in top of the file // jshint ignore: start but I don't want to write this in every single file, I want to disable it for all the project. Any idea of how can I do it?
As mentioned by OdatNurd the file won't do nothing by itself, it has to be loaded through the sublime project option in menu.
There is a newer, easier syntax for this. In your sublime project file add the following under settings.
{
"settings":
{
"SublimeLinter.linters.jshint.disable": true
}
}

shimming linkurious - how to configure?

I'm trying to use the linkurious library (a sigma fork), which provides a "main": "dist/sigma.require.js" (in the package.json). this allows me to do:
var sigma = require('linkurious');
however, the plugins are not included so I have to require them separately. the problem is that the plugins rely on the sigma variable being available in the global scope. so I've shimmed things as follows (from the package.json):
"browser": {
"sigma": "./node_modules/linkurious/dist/sigma.js",
"linkurious/plugins": "./node_modules/linkurious/dist/plugins.js"
},
"browserify-shim": {
"sigma": {"exports": "sigma"},
"linkurious/plugins": { "depends": [ "sigma" ] }
},
"browserify": {
"transform": [ "browserify-shim" ]
},
which, when run in a browser doesn't generate errors during inclusion of the plugins (I gather this means the global variable is available) but references to the plugins fail (as if they failed to attach themselves, or attached themselves to a non-global variable).
I'm using grunt-browserify to run the process where I have it configured like this (from the Gruntfile.js):
grunt.initConfig({
browserify: {
libs: {
files: { 'inc.js': ['index.js'] },
},
}
});
I've attached a little project to this issue with the minimal required code to demonstrate the problem in the hopes that someone else can replicate/figure out. unpack, type npm install; npm start and run a browser against http://localhost:8002/ to see the issue.
thanks in advance,
ekkis
sigma.zip
- edit I -
incidentally, bendrucker at the git repo (see: https://github.com/thlorenz/browserify-shim/issues/215) suggests I need to do a global transform. It's been explained to me that shimming doesn't work on node_modules files and for those I need a global transform. this doesn't make much sense to me as the whole point of shimming is that you don't own the code you're shimming. in any case, bendrucker pointed me to this other SO post where the question is posed but no answers are provided.
help?

jshint and sublimelinter settings config on mac

I'm trying to configure sublimelinter, specifically jshint on my Mac. On my windows version of SublimeText there is the following section in SublimeLinter.sublime-settings
"jshint_options":
{
// To fix column positions for JSHint errors you may want to add `"indent": 1` to your
// **User** "jshint_options". This issue affects users with tabs for indentation.
// This fix was reverted due to a conflict with using the `"white": true` option.
// "indent": 1,
"evil": true,
"regexdash": true,
"browser": true,
"wsh": true,
"trailing": true,
"sub": true
},
When I view the file on my Mac this section doesn't exist, is there a place to edit these option on the Mac version without a separate settings file? Or a global settings file for jshint?
I've been digging through similar questions but haven't found a clear solution.
Update:
Actually it doesn't seem to catch any errors at all when using it on the console. My javascript file doesn't end in .js how can I configure it to look at different extensions? I can't find it in the docs.
There's another way to set options globally, without using ".jshintrc" files.
1) create a file with any name (e.g. "jshint.conf"). my file is:
{
"globals": { "$": false },
"globalstrict": true,
"devel": true
}
2) put it anywhere. in my case it is: "c:\Users\Smith\AppData\Roaming\Sublime Text 3\Packages\User\"
3) make the next reference in section "jshint"->"args" of sublime-linter user setting (user/SublimeLinter.sublime-settings):
{
"user": {
"linters": {
"jshint": {
"args": [
"--config", "c:\\Users\\Smith\\AppData\\Roaming\\Sublime Text 3\\Packages\\User\\jshint.conf"
]
}
}
}
}
4) Enjoy!
In general I would recommend against configuring JSHint system-wide. It's usually safer to create a .jshintrc file for each project your work on because it's likely they will have different JSHint requirements.
The jshint_options SublimeLinter setting you mention in your question is from the old version of SublimeLinter, which has recently been reworked to have a simple plugin architecture. The JSHint plugin (which I assume you are using, since the settings you tried didn't work) makes the same recommendation:
You can configure jshint options in the way you would from the command line, with .jshintrc files.
The added benefit of this approach is that you can commit the .jshintrc file to your repository and ensure that anyone who works on the project is working with the same JSHint rules, rather than their own system-wide settings.

Resources