How to suppress warnings in sublimelinter using eslint? - sublimetext3

I'm using sublime as my IDE, and have downloaded sublimelinter for linting my javascript with eslint. In the sublimelinter.sublimesettings file, I have it configured to use eslint shown below:
{
"user": {
"debug": false,
"delay": 0.25,
"error_color": "D02000",
"gutter_theme": "Packages/SublimeLinter/gutter-themes/Default/Default.gutter-theme",
"gutter_theme_excludes": [],
"lint_mode": "load/save",
"linters": {
"eslint": {
"#disable": false,
"args": [],
"excludes": [],
}
},
"mark_style": "outline",
"no_column_highlights_line": false,
"passive_warnings": true,
"paths": {
"linux": [],
"osx": [],
"windows": []
},
"python_paths": {
"linux": [],
"osx": [],
"windows": []
},
"rc_search_limit": 3,
"shell_timeout": 10,
"show_errors_on_save": false,
"show_marks_in_minimap": true,
"syntax_map": {
"html (django)": "html",
"html (rails)": "html",
"html 5": "html",
"javascript (babel)": "javascript",
"magicpython": "python",
"php": "html",
"python django": "python",
"pythonimproved": "python"
},
"warning_color": "000000",
"wrap_find": true
}
}
My problem is I can't find anything online to suppress the warnings that come from eslint. I've tried using "ignore": "W" as a value within eslint but it didn't work. Eslint works fine, I just can't seem to find a solution to suppressing the warnings. Any ideas?
EDIT:
Here's my .eslintrc file:
{
/* Don't search any further for .eslintrc files */
"root": true,
/* See all the pre-defined configs here: https://www.npmjs.com/package/eslint-config-defaults */
"extends": [
"eslint:recommended",
"defaults/configurations/google"
],
"ecmaFeatures": {
"jsx": true
},
"env": {
"browser": true,
"node": true,
"es6": true
},
"globals":{
"angular": 1,
"phoenix": 1,
"requirejs": 1
},
"rules": {
"indent": [
2,
2,
{ "SwitchCase": 1 }
],
/* We don't do this consistently, so disable it as it is treated as an error otherwise */
"newline-after-var": 0,
"dot-location": [2, "property"],
"no-extra-semi": 1,
"semi": 2,
"max-len": [2, 250, 2],
"eqeqeq": 2,
"comma-dangle": 1,
"no-console": 0,
"no-debugger": 1,
"no-extra-parens": 1,
"no-irregular-whitespace": 0,
"no-undef": 1,
"no-unused-vars": 2,
"semi-spacing": 1
}
}

The --quiet flag will suppress all warnings, but does not silence errors. Via the command line, you can run:
eslint --quiet
Alternatively, to have this flag automatically appended, add "quiet" to the args of the ESLint configuration, so you don't have to remember to add the flag each time.

Related

Eslint Failed to load plugin 'security' declared in '.eslintrc': Cannot find module 'eslint-plugin-security'

My eslint don't work, and I don't know why.
Here is my eslint file:
{
"parser": "babel-eslint",
"plugins": [
"security",
"react",
"import",
"material-ui",
"eslint-plugin-no-inline-styles"
],
"extends": [
"airbnb",
"plugin:security/recommended",
"plugin:import/react",
"plugin:import/recommended"
],
"env": {
"browser": true,
"node": true,
"mocha": true
},
"rules": {
"jsx-a11y/media-has-caption": 0,
"import/no-extraneous-dependencies": 0,
"security/detect-object-injection": 0,
"security/detect-child-process": 0,
"security/detect-non-literal-regexp": 0,
"react/jsx-props-no-spreading": 0,
"react/jsx-filename-extension": 0,
"react/jsx-indent": 0,
"react/jsx-indent-props": 0,
"no-tabs": 0,
"indent": 0,
"no-underscore-dangle": 0,
"max-len": 0,
"jsx-quotes": 0,
"react/sort-comp": 0,
"no-debugger": 0,
"import/prefer-default-export": 0,
"arrow-body-style": 0,
"react/jsx-wrap-multilines": 0,
"spaced-comment": 0,
"class-methods-use-this": 0,
"padded-blocks": 0,
"eol-last": 0,
"no-lone-blocks": 0,
"implicit-arrow-linebreak": 0,
"no-plusplus": 0,
"default-case": 0,
"radix": 0,
"arrow-parens": [
"error",
"always"
],
"no-restricted-imports": [
"error",
{
"patterns": [
"#material-ui/*/*/*",
"!#material-ui/core/test-utils/*"
]
}
],
"react/destructuring-assignment": [
0,
"never",
{
"ignoreClassFields": true
}
],
"react/jsx-no-duplicate-props": [
2,
{
"ignoreCase": false
}
],
"no-inline-styles/no-inline-styles": 2
},
"settings": {
"import/resolver": {
"webpack": {
"extensions": [
".js",
".jsx"
]
}
},
"import/extensions": [
".js",
".jsx"
]
}
}
For some reason I get the following error:
Failed to load plugin 'security' declared in '.eslintrc': Cannot find module 'eslint-plugin-security'
I tried to install eslint-plugin-security globally but it didn't solve the issue.
Any Help?
Thanks.
adding "eslint-plugin-security" as a dev dependancy fixed my issue.
yarn add eslint-plugin-security --dev
or
npm install eslint-plugin-security --save-dev
will work
Solved it by changing the eslint file to the following:
{
"parser": "babel-eslint",
"plugins": [
"security",
"react",
"import",
"material-ui",
"eslint-plugin-no-inline-styles"
],
"extends": [
"airbnb",
"plugin:security/recommended",
"plugin:import/react",
"plugin:import/recommended"
],
"env": {
"browser": true,
"node": true,
"mocha": true
},
"rules": {
"jsx-a11y/media-has-caption": 0,
"import/no-extraneous-dependencies": 0,
"security/detect-object-injection": 0,
"security/detect-child-process": 0,
"security/detect-non-literal-regexp": 0,
"react/jsx-props-no-spreading": 0,
"arrow-parens": ["error", "always"],
"no-restricted-imports": [
"error",
{
"patterns": ["#material-ui/*/*/*", "!#material-ui/core/test-utils/*"]
}
],
"react/destructuring-assignment": [2, "never", { "ignoreClassFields": true }],
"react/jsx-no-duplicate-props": [2, { "ignoreCase": false }],
"no-inline-styles/no-inline-styles": 2,
"react/jsx-key": [2, { "checkFragmentShorthand": true }],
"react/no-unsafe": [2, { "checkAliases": true }]
},
"settings": {
"import/resolver": {
"webpack": {
"extensions": [
".js",
".jsx"
]
}
},
"import/extensions": [
".js",
".jsx"
]
}
}

ESLINT: ESLINT Error: ESLint configuration in ..\..\..\..\.eslintrc is invalid: - Unexpected top-level property "import/extensions"

im using airbnb-eslint along with babel-plugin-module-resolver. I get this error in every js file where i've used an alias to import.
{
"extends": ["plugin:import/errors", "plugin:import/warnings", "airbnb", "airbnb/hooks", "prettier", "plugin:prettier/recommended", "prettier/react", "plugin:react/recommended"],
"plugins": ["import", "react", "jsx-a11y", "react-hooks", "babel", "module-resolver"],
"rules": {
"react/jsx-filename-extension": [
2,
{
"extensions": [".js", ".jsx"]
}
],
"react/prop-types": 0,
"implicit-arrow-linebreak": 0,
"prefer-destructuring": 1,
"react/no-unused-state": 1,
"react/destructuring-assignment": 1,
"react/no-array-index-key": 1,
"react/jsx-key": [2],
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"react/jsx-no-duplicate-props": [2],
"react/jsx-uses-vars": [2],
"react/jsx-uses-react": [2],
"react/jsx-no-undef": ["error", { "allowGlobals": true}],
"react/no-direct-mutation-state": [2],
"react/require-optimization": [1],
"react/require-render-return": [2],
"jsx-a11y/img-has-alt": [0],
"jsx-a11y/img-redundant-alt": [2],
"no-nested-ternary": "off",
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
"no-underscore-dangle": ["error", { "allowAfterThis": true }],
"no-unused-expressions": ["error", {
"allowShortCircuit": true,
"allowTernary": true,
"allowTaggedTemplates": true
}],
"no-use-before-define": [
"error",
{ "functions": true, "classes": true, "variables": false }
],
"import/imports-first": ["error", "absolute-first"],
"import/no-unresolved": 0,
"import/newline-after-import": "error",
"import/prefer-default-export": 0,
"import/no-cycle": [2, { "maxDepth": 1, "ignoreExternal": true }],
"import/no-absolute-path": [2, { "esmodule": false, "commonjs": false, "amd": false }],
"prettier/prettier": ["error", {}, {
"usePrettierrc": true
}],
"quotes": [
"error",
"single",
{ "avoidEscape": true, "allowTemplateLiterals": false }
],
"max-len": ["error", {"code": 205, "ignoreUrls": true}],
"no-tabs": ["error", {"allowIndentationTabs": true}],
"babel/arrow-parens": [0, "as-needed"],
"babel/no-unused-expressions": 1,
"babel/valid-typeof": 1,
"module-resolver/use-alias": 2
},
"globals": {
"window": true,
"document": true,
"localStorage": true,
"FormData": true,
"FileReader": true,
"Blob": true,
"navigator": true
},
"env": {
"es2020": true,
"node": true,
"browser": true
},
"settings": {
"react": {
"version": "16.13.1"
},
"import/resolver": {
"babel-module": {
"root": ["."],
"alias": {
"#assets": "./src/assets",
"#config": "./src/config",
"#constants": "./src/constants",
"#hooks": "./src/hooks",
"#sharedComponents": "./src/sharedComponents",
"#commonActions": "./src/app/CommonActions",
"#pages":"./src/app/Pages",
"#utils": "./src/utils"
}
},
"node": {
"root": ["."],
"extensions": [
".js",
".jsx"
]
}
}
},
"parser": "babel-eslint",
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
"jsx": true,
"modules": true
}
}
}
This error does not come when using on mac..... only when using Linux/Windows. Due to this error eslint stops working in VSCode.
Error: ESLINT Error: ESLint configuration in .........eslintrc is invalid: - Unexpected top-level property "import/extensions".
Try adding root: true, as this will stop eslint looking for Global configs outside of your project

Incorrect version of jest trying to run jest

I have jest tests in my angular project.
I have a package.json file specifying the version of jest I would like to use to run the test. The file includes:
"#types/jest": "^24.0.18",
"jest": "^24.9.0",
"jest-preset-angular": "^7.1.1",
The jest config also includes:
"setupFilesAfterEnv": [
"<rootDir>/setup-jest.ts"
],
This is where the issue occurs. When trying to run jest, I get the following message:
● Validation Warning:
Unknown option "setupFilesAfterEnv" with value ["<rootDir>/setup-jest.ts"] was found.
This is probably a typing mistake. Fixing it will remove this message.
Configuration Documentation:
https://jestjs.io/docs/configuration.html
I had a look at jest -h and found a flag which gives me the setup of the jest environment.
jest --showConfig
This however shows that I am running jest on version
"version": "23.6.0"
So my question lies here. How come after I do an npm i, the jest version trying to run the tests is different / old.
I tried installing jest-cli with the -g flag and the save-dev flag.
Also trying to run tests in VS Code, if thats any help.
Please help.
Thank you in advance.
Full log of npx jest --showConfig
● Validation Warning:
Unknown option "setupFilesAfterEnv" with value ["<rootDir>/setup-jest.ts"] was found.
This is probably a typing mistake. Fixing it will remove this message.
Configuration Documentation:
https://jestjs.io/docs/configuration.html
{
"configs": [
{
"automock": false,
"browser": false,
"cache": true,
"cacheDirectory": "/var/folders/bs/wrvrgl6132df8l5ndxv40m3m0000gn/T/jest_dx",
"clearMocks": false,
"coveragePathIgnorePatterns": [
"/node_modules/",
"setup-jest.ts"
],
"detectLeaks": false,
"detectOpenHandles": false,
"errorOnDeprecated": false,
"filter": null,
"forceCoverageMatch": [],
"globals": {
"ts-jest": {
"tsConfig": "<rootDir>/tsconfig.spec.json",
"stringifyContentPathRegex": "\\.html$",
"astTransformers": [
"jest-preset-angular/InlineHtmlStripStylesTransformer"
]
}
},
"haste": {
"providesModuleNodeModules": []
},
"moduleDirectories": [
"node_modules"
],
"moduleFileExtensions": [
"ts",
"html",
"js",
"json"
],
"moduleNameMapper": [
[
"#app/(.*)",
"/Users/name/Projects/project/src/app/$1"
],
...
],
"modulePathIgnorePatterns": [],
"name": "6caa4...",
"prettierPath": "/Users/name/Projects/project/node_modules/prettier/index.js",
"resetMocks": false,
"resetModules": false,
"resolver": null,
"restoreMocks": false,
"rootDir": "/Users/name/Projects/project",
"roots": [
"/Users/name/Projects/project"
],
"runner": "jest-runner",
"setupFiles": [],
"setupTestFrameworkScriptFile": null,
"skipFilter": false,
"snapshotSerializers": [],
"testEnvironment": "/Users/name/Projects/project/node_modules/jest-environment-jsdom-thirteen/build/index.js",
"testEnvironmentOptions": {},
"testLocationInResults": false,
"testMatch": [
"**/__tests__/**/*.js?(x)",
"**/?(*.)+(spec|test).js?(x)"
],
"testRegex": "",
"testRunner": "/Users/name/node_modules/jest-jasmine2/build/index.js",
"testURL": "http://localhost",
"timers": "real",
"transform": [
[
"^.+\\.(ts|js|html)$",
"/Users/name/Projects/project/node_modules/ts-jest/dist/index.js"
]
],
"watchPathIgnorePatterns": []
}
],
"globalConfig": {
"bail": false,
"changedFilesWithAncestor": false,
"collectCoverage": true,
"collectCoverageFrom": null,
"coverageDirectory": "/Users/name/Projects/project/coverage",
"coverageReporters": [
"json",
"text",
"lcov",
"clover"
],
"coverageThreshold": null,
"detectLeaks": false,
"detectOpenHandles": false,
"errorOnDeprecated": false,
"expand": false,
"filter": null,
"globalSetup": null,
"globalTeardown": null,
"listTests": false,
"maxWorkers": 7,
"noStackTrace": false,
"nonFlagArgs": [],
"notify": false,
"notifyMode": "always",
"passWithNoTests": false,
"projects": null,
"rootDir": "/Users/name/Projects/project",
"runTestsByPath": false,
"skipFilter": false,
"testFailureExitCode": 1,
"testPathPattern": "",
"testResultsProcessor": null,
"updateSnapshot": "new",
"useStderr": false,
"verbose": null,
"watch": false,
"watchman": true
},
"version": "23.6.0"
}
Showing npm config get log here too:
; cli configs
metrics-registry = "http://.../.../npm-group/"
scope = ""
user-agent = "npm/6.9.0 node/v10.15.3 darwin x64"
; project config /Users/user/Projects/project/.npmrc
registry = "http://.../.../npm-group/"
; node bin location = /Users/user/.nvm/versions/node/v10.15.3/bin/node
; cwd = /Users/user/Projects/project
; HOME = /Users/user
; "npm config ls -l" to show all defaults.
I had the same issue, after a long search I've tried this:
type jest
Which gave me the location:
/usr/local/bin/jest
Renaming this file (or deleting it), solved the problem (note that now running jest will give command not found).

JSHint options do not apply (Sublime3)

I've installed SublimeLinter and SublimeLinter-jshint and JSHint itself works. However, i'm not able to configure JSHint. I tried to add jshint settings to SublimeLinter.sublime-settings but it seems that there is no effect on JSHint.
This is what my settings (Preferences > Package Settings > SublimeLinter > Settings - User) look like:
{
"user": {
"debug": false,
"delay": 0.25,
"error_color": "D02000",
"gutter_theme": "Packages/SublimeLinter/gutter-themes/Default/Default.gutter-theme",
"gutter_theme_excludes": [],
"lint_mode": "background",
"linters": {
"jshint": {
"#disable": false,
"args": [],
"excludes": [],
"maxdepth": 1,
"strict": "global",
"sub": true
}
},
"mark_style": "outline",
"no_column_highlights_line": false,
"passive_warnings": false,
"paths": {
"linux": [],
"osx": [],
"windows": []
},
"python_paths": {
"linux": [],
"osx": [],
"windows": []
},
"rc_search_limit": 3,
"shell_timeout": 10,
"show_errors_on_save": false,
"show_marks_in_minimap": true,
"syntax_map": {
"html (django)": "html",
"html (rails)": "html",
"html 5": "html",
"javascript (babel)": "javascript",
"magicpython": "python",
"php": "html",
"python django": "python",
"pythonimproved": "python"
},
"warning_color": "DDB700",
"wrap_find": true
}
}
I've added some example settings like '"maxdepth": 1', but these rules do not apply. What is missing here?
From the Settings section of the README on Github, also available on the Package Control page:
You can configure jshint options in the way you would from the command line, with .jshintrc files. For more information, see the jshint docs. The linter plugin does this by searching for a .jshintrc file [...]
Read the full section and the linked docs for all the directions, then place a .jshintrc file where appropriate for your project.

SublimeLinter ignore missing semicolons

I'm using a non-semicolon based coding style in one of my node apps, but the problem is SublimeLinter is logging all the missing semicolons, and eventually stops with a "Too many errors" error, and stops linting the rest of the script.
I've tried adding an ignore_match object to both the default and user settings, but nothing works. I've also restarted after each time I've tried just to make sure.
I've even tried adding it to the excludes portion of the settings.
This is the resource I was using:
Linter Settings
Here is one of the errors I'm getting:
Z:\www\site\node\workers.js: line 162, col 2, Missing semicolon. (W033)
Here's my settings: From User.
{
"user": {
"debug": true,
"delay": 0.25,
"error_color": "D02000",
"gutter_theme": "Packages/SublimeLinter/gutter-themes/Default/Default.gutter-theme",
"gutter_theme_excludes": [],
"ignore_match": [
"Missing semicolon."
],
"lint_mode": "background",
"linters": {
"annotations": {
"#disable": false,
"args": [],
"errors": [
"FIXME"
],
"excludes": ["Missing semicolon"],
"warnings": [
"TODO",
"README"
]
},
"jshint": {
"#disable": false,
"args": [],
"excludes": ["Missing semicolon"]
},
"php": {
"#disable": false,
"args": [],
"excludes": []
}
},
"mark_style": "outline",
"no_column_highlights_line": false,
"passive_warnings": false,
"paths": {
"linux": [],
"osx": [],
"windows": []
},
"python_paths": {
"linux": [],
"osx": [],
"windows": []
},
"rc_search_limit": 3,
"shell_timeout": 10,
"show_errors_on_save": false,
"show_marks_in_minimap": true,
"syntax_map": {
"html (django)": "html",
"html (rails)": "html",
"html 5": "html",
"php": "html",
"python django": "python"
},
"warning_color": "DDB700",
"wrap_find": true
}
}
EDIT:
Added ignore_match": ["Missing semicolon"] to the jshint options. It became:
"jshint": {
"#disable": false,
"args": [],
"excludes": [],
"ignore_match": ["Missing semicolon"]
},
Complete answer,
Full user settings json file:
{
"user": {
"linters": {
"jshint": {
"#disable": false,
"ignore_match": [
".*Missing.*",
]
},
}
}
}
Easy answer:
Add ignore_match": ["Missing semicolon"] to jshint options.
"jshint": {
"#disable": false,
"args": [],
"excludes": [],
"ignore_match": ["Missing semicolon"]
},

Resources