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"]
},
Related
I have a relatively simple Node.js application in which I'm trying to use Jest for my unit tests (since I use it on my other client project and would like the consistency of using it here). To try to get to the bottom of it, I have tried to create a stripped-down project with the bare minimum to reproduce the problem.
My package.json is here:
{
"name": "jest-sample",
"version": "0.2.0",
"private": true,
"description": "NodeJS backend to the Service Manager UI",
"author": "Me",
"license": "SEE LICENSE IN LICENSE",
"deprecated": false,
"main": "src/js/app.js",
"type": "module",
"engines": {
"node": "^8.15.1"
},
"scripts": {
"test": "npx jest"
},
"devDependencies": {
"jest": "26.0.1",
"supertest": "4.0.2"
},
"jest": {
"testEnvironment": "node"
}
}
I don't have eslint or anything else in the project.
➜ jest-sample ls -a
. .. __tests__ node_modules package-lock.json package.json
The test is also simple:
describe('Sample Test', function() {
it('should be', function() {
expect(true).toBe(true);
})
});
Yet, when I run jest, I get:
➜ jest-sample npx jest
FAIL __tests__/sample.spec.js
● Test suite failed to run
ReferenceError: describe is not defined
> 1 | describe('Sample Test', function() {
| ^
2 | it('should be', function() {
3 | expect(true).toBe(true);
4 | })
at Object.<anonymous> (__tests__/sample.spec.js:1:1)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 2.562 s
Ran all test suites.
UPDATE:
The output of jest-debug is below:
➜ jest-sample npx jest --debug
{
"configs": [
{
"automock": false,
"cache": true,
"cacheDirectory": "/private/var/folders/4m/6tytrddj3g90b8rmbrccw3lm0000gn/T/jest_dx",
"clearMocks": false,
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"cwd": "/Users/rbair/Projects/gitlab/iot/infrastructure/service-manager/jest-sample",
"detectLeaks": false,
"detectOpenHandles": false,
"errorOnDeprecated": false,
"extraGlobals": [],
"forceCoverageMatch": [],
"globals": {},
"haste": {
"computeSha1": false,
"throwOnModuleCollision": false
},
"moduleDirectories": [
"node_modules"
],
"moduleFileExtensions": [
"js",
"json",
"jsx",
"ts",
"tsx",
"node"
],
"moduleNameMapper": [],
"modulePathIgnorePatterns": [],
"name": "d652708218018aa212b40c53d7999ccc",
"prettierPath": "prettier",
"resetMocks": false,
"resetModules": false,
"restoreMocks": false,
"rootDir": "/Users/rbair/Projects/gitlab/iot/infrastructure/service-manager/jest-sample",
"roots": [
"/Users/rbair/Projects/gitlab/iot/infrastructure/service-manager/jest-sample"
],
"runner": "jest-runner",
"setupFiles": [],
"setupFilesAfterEnv": [],
"skipFilter": false,
"snapshotSerializers": [],
"testEnvironment": "/Users/rbair/Projects/gitlab/iot/infrastructure/service-manager/jest-sample/node_modules/jest-environment-node/build/index.js",
"testEnvironmentOptions": {},
"testLocationInResults": false,
"testMatch": [
"**/__tests__/**/*.[jt]s?(x)",
"**/?(*.)+(spec|test).[tj]s?(x)"
],
"testPathIgnorePatterns": [
"/node_modules/"
],
"testRegex": [],
"testRunner": "/Users/rbair/Projects/gitlab/iot/infrastructure/service-manager/jest-sample/node_modules/jest-jasmine2/build/index.js",
"testURL": "http://localhost",
"timers": "real",
"transform": [
[
"^.+\\.[jt]sx?$",
"/Users/rbair/Projects/gitlab/iot/infrastructure/service-manager/jest-sample/node_modules/babel-jest/build/index.js",
{}
]
],
"transformIgnorePatterns": [
"/node_modules/"
],
"watchPathIgnorePatterns": []
}
],
"globalConfig": {
"bail": 0,
"changedFilesWithAncestor": false,
"collectCoverage": false,
"collectCoverageFrom": [],
"coverageDirectory": "/Users/rbair/Projects/gitlab/iot/infrastructure/service-manager/jest-sample/coverage",
"coverageProvider": "babel",
"coverageReporters": [
"json",
"text",
"lcov",
"clover"
],
"detectLeaks": false,
"detectOpenHandles": false,
"errorOnDeprecated": false,
"expand": false,
"findRelatedTests": false,
"forceExit": false,
"json": false,
"lastCommit": false,
"listTests": false,
"logHeapUsage": false,
"maxConcurrency": 5,
"maxWorkers": 3,
"noStackTrace": false,
"nonFlagArgs": [],
"notify": false,
"notifyMode": "failure-change",
"onlyChanged": false,
"onlyFailures": false,
"passWithNoTests": false,
"projects": [],
"rootDir": "/Users/rbair/Projects/gitlab/iot/infrastructure/service-manager/jest-sample",
"runTestsByPath": false,
"skipFilter": false,
"testFailureExitCode": 1,
"testPathPattern": "",
"testSequencer": "/Users/rbair/Projects/gitlab/iot/infrastructure/service-manager/jest-sample/node_modules/#jest/test-sequencer/build/index.js",
"updateSnapshot": "new",
"useStderr": false,
"watch": false,
"watchAll": false,
"watchman": true
},
"version": "26.0.1"
}
FAIL __tests__/sample.spec.js
● Test suite failed to run
ReferenceError: describe is not defined
> 1 | describe('Sample Test', function() {
| ^
2 | it('should be', function() {
3 | expect(true).toBe(true);
4 | })
at Object.<anonymous> (__tests__/sample.spec.js:1:1)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.523 s
Ran all test suites.
As discovered by #jonrsharpe, my underlying problem was the version of Node I was using (10.13.0). By updating to version 12.18.0, the issue went away.
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).
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.
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.
Browsersync is working fine with a PHP/Symfony 3 project with the following command:
browser-sync start --proxy http://localhost:8000 --files "web/css/**/*.css"
The browser will open at http://localhost:3000 and if I change something in web/css I can see the updated stylesheets without a full page reload. So far so good.
However it doesn't work with the following bs-config.js:
module.exports = {
"files": [
"web/css/**/*.css"
],
"server": false,
"proxy": "http://localhost:8000"
};
And the command:
browser-sync start
Browser will not load, changes aren't detected and reloading doesn't work. What I'm missing?
try this:
1º Create "bs-config.js" with: browser-sync init
2º Open file and edit like this:
module.exports = {
"ui": {
"port": 3001,
"weinre": {
"port": 8080
}
},
"files": "web/css/**/*.css",
"watchOptions": {},
"server": false,
"proxy": "http://localhost:8000",
"port": 3000,
"middleware": false,
"serveStatic": [],
"ghostMode": {
"clicks": true,
"scroll": true,
"forms": {
"submit": true,
"inputs": true,
"toggles": true
}
},
"logLevel": "info",
"logPrefix": "BS",
"logConnections": false,
"logFileChanges": true,
"logSnippet": true,
"rewriteRules": [],
"open": "local",
"browser": "default",
"cors": false,
"xip": false,
"hostnameSuffix": false,
"reloadOnRestart": false,
"notify": true,
"scrollProportionally": true,
"scrollThrottle": 0,
"scrollRestoreTechnique": "window.name",
"scrollElements": [],
"scrollElementMapping": [],
"reloadDelay": 0,
"reloadDebounce": 0,
"reloadThrottle": 0,
"plugins": [],
"injectChanges": true,
"startPath": null,
"minify": true,
"host": null,
"localOnly": false,
"codeSync": true,
"timestamps": true,
"clientEvents": [
"scroll",
"scroll:element",
"input:text",
"input:toggles",
"form:submit",
"form:reset",
"click"
],
"socket": {
"socketIoOptions": {
"log": false
},
"socketIoClientConfig": {
"reconnectionAttempts": 50
},
"path": "/browser-sync/socket.io",
"clientPath": "/browser-sync",
"namespace": "/browser-sync",
"clients": {
"heartbeatTimeout": 5000
}
},
"tagNames": {
"less": "link",
"scss": "link",
"css": "link",
"jpg": "img",
"jpeg": "img",
"png": "img",
"svg": "img",
"gif": "img",
"js": "script"
}};
3º Run the server: php -S localhost:8000
4º Start BrowserSync: browser-sync start --config bs-config.js