jshint and sublimelinter settings config on mac - sublimetext3

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.

Related

ESLint in VSCode not fixing on save

I am using ESLint in my Vue(Nuxt) project in VSCode. When I save I would like my ESLint to run automatically and fix all the warnings for me automatically.
This is my settings.json file in VSCode:
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"vetur.format.defaultFormatter.js": "vscode-typescript",
"vetur.validation.template": false,
"vetur.completion.scaffoldSnippetSources": {},
"vetur.completion.useScaffoldSnippets": false,
"vetur.format.defaultFormatter.html": "none",
"workbench.iconTheme": "material-icon-theme",
"git.autofetch": true,
"git.defaultCloneDirectory": "",
"gitlens.views.repositories.files.layout": "list",
"editor.tabSize": 2,
"editor.detectIndentation": false,
}
And this is my .eslintrc.js file:
module.exports = {
root: true,
env: {
browser: true,
node: true,
},
extends: [
"#nuxtjs",
"plugin:nuxt/recommended",
"../.eslintrc.js"
],
rules: {
//Add custom rules for the frontend here.
//Rules that are common for shared, frontend and backend should go in the parent file
"nuxt/no-cjs-in-config": "off",
},
}
The linked ../.eslintrc.js file contains the following:
module.exports = {
parserOptions: {
parser: 'babel-eslint',
},
plugins: ['jest'],
rules: {
'prefer-const': 'off',
'comma-dangle': ['error', 'always-multiline'],
'prefer-template': 'error',
},
env: {
'jest/globals': true
}
}
Whenever I save the file the warnings just show up and will not automatically fix themselves.
EDIT:
I've turned on verbose output and i'm seeing this in the output:
(node:6832) UnhandledPromiseRejectionWarning: Error: Failed to load plugin 'import' declared in 'frontend\.eslintrc.js » #nuxtjs/eslint-config': Cannot find module 'eslint-plugin-import'
Require stack:
I've then ran yarn add eslint-plugin-import and tried again, it still returns the same error.
Get eslint plugin, add this code to your settings.json
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": ["javascript"]
}
source
Launch VSCode,
Command + Shift + P, type settings and hit enter, paste and save the following:
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
}
}
You're good to go!
I've managed to fix the issue.
The problem was that there were multiple working directories in my solution, which all have their own eslint config.
Putting the following line in the settings.json file of VSCode solved my issue:
"eslint.workingDirectories": [{ "mode": "auto" }]
I tried those solutions and others, and it still didn't work. Actually it was just that ESLint's use had to be approved for use in VSCode. That is, I clicked on the ESLint item on the editor's bottom bar:
Which opened a popup asking me to approve ESLint. After approval autocorrect was running as expected.
Install ESLint extension from the VSCode marketplace.
Once the ESLint extension has installed you may use CTRL + SHIFT + P to open the Command Palette. Search “ESLint fix all auto-fixable Problems” and press enter.
This command would enable eslint to fix the file on save.
In the snap above as you can see that I am getting eslint errors and just to inform you all that despite saving the file, all auto-fixable problems are were not getting fixed by eslint/prettier setup.
So I tried pressing ctrl+shift+p and selecting prettier as default formatter and also tried doing eslint restart server but that didn't worked.
I noticed that vscode was giving me some notifications at the bottom right corner (bell icon). I clicked on that and some list of pop up came up stating that there are multiple formatters installed for the same extension file. Like for example in the below snap there is .jsx file(it had two formatters one was prettier and other was vscodes inbuilt formatter). I clicked on configure button and selected prettier as default and when I saved the file it worked!
If this doesn't works for you then I think this all worked for me because I had eslint npm packages installed in my project that works with prettier to enforce the prettier rules. (these packages are eslint-config-prettier and eslint-plugin-prettier)
I ran into a similar problem-- ESLint was not properly formatting only certain, seemingly random, files on save. Running ESLint --fix would fix the formatting errors, but saving would not. Adding this line to our workspace settings.json fixed the problem:
"eslint.format.enable": true,
Making all our formatter settings look like this:
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": true
},
"eslint.format.enable": true,
You can also go into the ESLint extension settings and check off the checkbox labeled ESLint > Format:Enable. Worked like a charm!
What fixed it for me was adding this to settings.json, because VSCode didn't know what formatter I wanted to be used on save:
"[javascript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
Check if in the settings.json there are other formatters enabled, in my case I had this by mistake.
"[javascript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"}
After getting the Eslint plugin you need to add this line to the settings.json:
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
}
Still not working? check if your eslint works fine by running this in the terminal:
eslint --ext \".js,.vue\" --ignore-path .gitignore .
If it failed with exit code 2 try removing node modules and install again.
After running this command you should see the eslint errors.
I was dealing with the same issue, and nothing seemed to help, even though I did all the configurations correctly, and ESLint was marking the problems in my files correctly.
For me the solution was to move the .vscode folder to the project root.
Now everything works as intended.

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

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
}
}

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

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.

Sublime -- Setting Default Syntax for *.hbs.html

I've started working with MeteorJS, which requires Handlebars templates to end with *.html.
You can't use *.hbs, or Meteor will throw an error.
I'd like to simply use *.hbs.html, so Meteor won't raise an exception, and I'll get the syntax highlighting for Handlebars simultaneously. How can I customize Sublime to recognize *.hbs.html as Handlebars syntax?
UPDATE:
Here's my code for ApplySyntax (not working yet):
"syntaxes": [
{
"name": "Handlebars",
"match": "all",
"rules": [
{"file_name": ".hbs.html$"}
]
}
]
Try this in ApplySyntax:
"syntaxes": [
{
"name": "Handlebars/Handlebars",
"extensions": ["hbs.html"]
}
]
The key is in the name - you need to specify the name of the package AND the path to the .tmLanguage file (extension excluded) within that package. I think it's in the root of the Handlebars package in this case, so this should work.
If you need other extensions just add them to that array, or if you need more complex matching you can use regular expressions as outlined in the other answer (or a combination of both).
By default Sublime Text only uses the last extension part to detect syntax, in your case, it's html.
There's a plugin called ApplySyntax that can detect syntax by any part of the filename, like hbs.html, apart from other things - see the default settings file for examples.
The ApplySyntax configuration should look like
"syntaxes": [
{
"name": "Handlebars",
"rules": [
{"file_name": ".*\\.hbs\\.html$"}
]
}
]
I was able to get this working without any extra packages. I'm using Sublime Text 3 Build 3126.
Open the file whose syntax you want to change
Go to View → Syntax → Open all with current extension as → select the appropriate syntax
Preferences → Settings - Syntax Specific
Change the extension as appropriate, for example:
{
"extensions":
[
"hbs.html"
]
}
Save the syntax settings file

Resources