Sublime Linter/ ReferenceError: window is not defined? - javascript

I know this is very basic question, but it's very strange that I cannot make it work, after spending hours, I really need help.
OSX 10.8.4
sublime Text 2 Version 2.0.2 Build 2221
node v0.10.15
jshint v2.1.7
Actually, I clean-installed sublime Text 2 just for this; just Sublime Package Control has been installed.
Firstly, I prepared a foo.js code:
function x(a, b)
{
return a + b
res = x(10, 20)
console.log("res = " + res);
which result:
$ jshint foo.js
foo.js: line 3, col 17, Missing semicolon.
foo.js: line 6, col 16, Missing semicolon.
foo.js: line 2, col 1, Unmatched '{'.
3 errors
So, jshint works as expected so far for the simple test.
I tried many things to get it work with Sublime Linter, but with no success, I clean-installed the sublime app, then followed a tutorial video:
https://tutsplus.com/lesson/sublime-linter/
Looks easy, and Sublime Linter appearrently successfully installed and readme appears as the video show at 00:30, but in my case, after that, saving or whatever never triggers anything.
Well, I'm totally lost. Please advise. Thanks.
UPDATE:
I noticed sublimeText console shown a error!
Traceback (most recent call last):
File "./SublimeLinter.py", line 431, in _update_view
File "./SublimeLinter.py", line 143, in run_once
File "./sublimelinter/modules/base_linter.py", line 291, in run
File "./sublimelinter/modules/javascript.py", line 72, in parse_errors
ValueError: Error from jshint: /Users/ken/Library/Application Support/Sublime Text 2/Packages/SublimeLinter/sublimelinter/modules/libs/jshint/jshint.js:7881
})(window)
^
ReferenceError: window is not defined
at Object.require.util (/Users/ken/Library/Application Support/Sublime Text 2/Packages/SublimeLinter/sublimelinter/modules/libs/jshint/jshint.js:7881:4)
EDIT:
ok, this seems bug, I should have checked there first..
https://github.com/SublimeLinter/SublimeLinter/issues

There is currently a workaround for this:
The hotfix for this is - in Linux installations - to add
global.window = {};
to the top of the file
~/.config/sublime-text-2/Packages/SublimeLinter/sublimelinter/modules/libs/jshint/jshint.js
For Windows or OS/X installations you need to find the location of your Sublime Text package configurations.

For those that are still getting this error, edit the JSHint configuration file and add the following option:
"jshint_options": {
"undef": true,
"unused": true,
"browser": true, /* Defines DOM globals such as window, navigator, FileReader, etc. */
"jquery": true, /* OPTIONAL: globals exposed by jQuery */
"devel": true, /* OPTIONAL: globals such as debugging, alert */
"globals": { /* OPTIONAL: set others that aren't predefined by JSHint */
"Modernizr": true
}
}
Learn more about the pre-defined JSHint global variables

Related

JavaScript color highlighting error in VScode

I have fresh install of VScode editor (v.1.14.2). Doesn't have any installed extensions. I have problem with javaScript highlighting in very simple file.
The same code in Sublime Text 3:
Default VScode theme (Dark+), doesn't have this bug, and all function names and methods have the same colors. But many another themes (monokai and Abyss for example) have this bug/feature.
I want to have for function names and methods the same color (line 10, 11, 13, 16). Ideally, all lines like in ST3 - blue (line 13 - green). But, it's ok if it would be a green.
I read scope naming link, try to compare different themes. Install all monokai-based themes, but all of theme, has this bug. I tried to create new one, but I didn't do what I need.
So, does it possible to fix this?
You can use vscode command Developer: Inspect TM Scopes for scope inspection. This color changes because vscode thinks click(), addEventListener()... is special DOM-related properties and should be highlighted.
Workaround would be modifying monokai-color-theme.json in
Microsoft VS Code\resources\app\extensions\theme-monokai\themes.
In this array "tokenColors": [] add:
{
"name": "DOM & invocation color fix",
"scope": "meta.function-call.js entity.name.function, meta.function-call.js support.function.dom.js",
"settings": {
"foreground": "#66D9EF"
}
}
This will make function calls & DOM-methods sublime-like.
P.S. If theme updates it will most likely overwrite this file.
Edit:
From some version it is possible to modify theme from settings.json Ctrl+,
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": ["meta.function-call.js entity.name.function",
"meta.function-call.js support.function.dom.js"],
"settings": {
"foreground": "#66D9EF"
}
}
]
}
Your function should not have an end-line ";" added. Your variable test however should have one, this is simple syntax error and doesn't always get caught. This post is years late but it came up in search and the above suggestion is too much work.

xo lint error: `document` is not defined

I've been a long time user of Standard, and now that I'm working on a new project, I've been asked to start writing semicolons.
I'm trying to use both xo, Babel and React, but I keep getting an error when I try to lint my code:
document is not defined. no-undef
I've tried adding an env option to the xo field in my package.json file, but no success.
My xo config:
"xo": {
"esnext": true,
"extends": "xo-react",
"space": true,
"rules": {
"react/jsx-space-before-closing": 0
}
}
It is cumbersome to specify linting options such as /** global document **/ and edit a configuration file every time you use a global.
This error can be suppressed by using --env=browser option:
xo --env=browser [<file|glob> ...]
Note: Same problem comes with Node.js, where the linter will complain that require and friends are not defined. The switch has to change to --env=node in that case.
However, XO defaults the env to node, therefore this will not be a problem in most cases. You will need multiple environments if your project contains both client and server files. in that case, --env switch can be set multiple times:
xo --env=browser --env=node [<file|glob> ...]
You have to define globals in ESLint. There are two ways to accomplish this, firstly as a comment in your code:
/* global document */
Or you can configure in configuration file like so:
{
"globals": {
"var1": true,
"var2": false
}
}
See the ESLint docs for more

How to disable JSLint ES6 errors with const and let in Adobe Brackets?

I have Googled and looked through this site everywhere, but I can only find answers for JSHint instead of JSLint.
To get rid of the "use function form of use strict" error I add in /*jslint node: true */.
But to disable errors for using const and let I can't seem to find anything. JSHint has esversion: 6 but this doesn't work on JSLint.
Use the Preferences API:
var PreferencesManager = brackets.getModule("preferences/PreferencesManager");
prefs = PreferencesManager.getExtensionPrefs("jslint");
prefs.set("options.es6", true);
Or set it one of the config files:
the brackets.json file of the user directory
or:
the .brackets.json file of the project directory:
As such:
{
"jslint.options": {
"es6": true
}
}
References
brackets: .brackets.json
brackets: jslint extension - main.js
brackets wiki: Preferences Overview
PreferencesManager - Brackets API

Enable white in jsLint in Sublime for all files

If I add /*jslint white: true*/ to my javascript code, jsLint stops complaining about using tabs instead of spaces. I would like to enable it globally so I do not have to repeat myself in every file. To edit jsLint's settings you can go to JSLint.sublime-settings - User.
I have added following to this file
{
"white" : true
}
However, jsLint is still complaining about using tabs. Is it possible to configure jsLint settings globally?
I am using Sublime Text 3 3083 on OS X 10.11.2
you can try this.
Preferences > Package Settings > JSLint > Settings > User
{
"jslint_options": "--white"
}

BusterJS freezes when a lib is included

I have the following setup:
buster.js:
var config = module.exports;
config["web-module"] = {
autoRun: true,
environment: "browser",
rootPath: ".",
libs: [
//"app/webroot/src/lib/underscore.js"
],
sources: [
],
tests: [
"buster_simpletest.js"
]
};
buster_simpletest.js:
buster.testCase("My thing", {
"states the obvious": function () {
console.log("TEST");
assert(true);
}
});
This setup runs fine and I get the expected console output:
Chrome 24.0.1312.57, Windows Server 2008 R2 / 7:
Passed: Chrome 24.0.1312.57, Windows Server 2008 R2 / 7 My thing states the obvious
[LOG] TEST
1 test case, 1 test, 1 assertion, 0 failures, 0 errors, 0 timeouts.
Finished in 0.004s
However, it doesn't as soon as I include any of the libs (I tried underscore.js, jQuery and several others.)
I don't get a single line of console output. No error, no nothing. It simply freezes there.
I also tried to disable autoRun and include a run.js which calls buster.run();, but the result was the same.
Does anyone know what's wrong here?
Thanks in advance for your help.
Edit:
Ok I tested some more and it seems to have problems with the folder depth. Here is my folder structure:
root
- buster.js
- buster_simpletest.js
- underscore.js
- a
- underscore.js
- b
- underscore.js
And here's my testing result:
libs: [
//"underscore.js" // works
//"a/underscore.js" // works
//"a/b/underscore.js" // freezes
//"a/b/xunderscore.js" // Error: "Failed loading configuration: "a/b/xunderscore.js" matched no files or resources"
]
As you can see it freezes as soon as I have depth of 2 folders. Although it is able to find the file, as I get an error if I try to include an invalid file.
Edit 2:
Seems to be a bug with windows only. The same setup works fine on our linux machine.
I guess we have to wait for proper windows support.

Categories

Resources