cfjedimaster / brackets-jshint Goto Github PK
View Code? Open in Web Editor NEWAdds JSHint support to Brackets
License: MIT License
Adds JSHint support to Brackets
License: MIT License
JSHint supports javascript style comments in .jshintrc. When a project contains such config file and brackets opens it, brackets-jshint fails to parse it because of comments.
Please use the following method to strip comments before you do JSON.parse in main.js
/**
* Removes JavaScript comments from a string by replacing
* everything between block comments and everything after
* single-line comments in a non-greedy way.
*
* English version of the regex:
* match '/*'
* then match zero or more instances of any character (incl. \n)
* except for instances of '* /' (without a space, obv.)
* then match '* /' (again, without a space)
*
* @param {string} str a string with potential JavaScript comments.
* @returns {string} a string without JavaScript comments.
*/
function removeComments(str) {
str = str || "";
str = str.replace(/\/\*(?:(?!\*\/)[\s\S])*\*\//g, "");
str = str.replace(/\/\/[^\n\r]*/g, ""); // Everything after '//'
return str;
}
This is the same approach jshint uses with its command line interface.
I considered giving a pull request, but somehow you are using non consistent line endings in main.js and it mess up the patch. So I did not bother.
@cfjedimaster : could we please add a license and copyright notice to the project?
I'm not submitting a PR since I'm not certain which license you'd like to have. If you'd confirm that it is MIT license, I can submit a PR to address this adding MIT license and the copyright notice to your name.
I have installed this extension from within Brackets, and for some reason my jshintrc
file is not getting picked up. Can you help me troubleshoot the problem?
Mixed spaces and tabs
errors of JSHint are not captured in the latest version of Brackets-JSHint. I am using Brackets JSHint version 2.2.5 and my Brackets version is .43
Hey,
If you make something like this:
if(a == b)
var x= 1;
else
var x= 2;
console.log(x);
he will complain about redefining of x. But I think he should detect that x always only once will be defined.
Hello,
I use Brackets 1.4 on Windows7.
I was not able to make jshint work until I made a change in the global "Preference File" (menu Debug > Open Preference file).
I use 'JsHint' instead of 'JSHint' here:
"language": {
"javascript": {
"linting.prefer": "JsHint",
"linting.usePreferredOnly": true
}
I am not sure if it is the right solution (should README.md be updated ?) or if I missed something.
Thank you for your attention.
When I search for "lint" or "linter" in the Available tab of the Extension Manager, this extension does not show up.
Adding it to a keywords
property in your package.json should fix it. I haven't actually tested if "lint" acts like a wildcard pattern, covering "lint", "linter", and "linting", or if you have to enter all three words. You will have to play around with it and see what works.
Also, for completeness, might want to consider adding a categories
property with value linting
. It's not used yet but, hey, why not? See https://github.com/adobe/brackets/wiki/Extension-package-format#categories.
It seems that only the one in the project root is picked.
It would be great if brackets-jshint could display the warning and error codes for each JSHint line similar to what grunt-contrib-jshint does. ie:
26 (W015) Expected 'case' to have an indentation at 25 instead at 29.
instead of the current
26 Expected 'case' to have an indentation at 25 instead at 29.
It would make it easier to identify the specific error/warning types.
It seems rather curious that a JSHint extension would not have its own .jshintrc for linting. Is it possible to add one so that users who want to contribute (namely me) know what kind of options I should pay attention to?
For sprint 26 you will have to update the table classes because bootstrap 2.3.1 will be pulled in see adobe/brackets#3672
If you like i could also submit a pull request once the update landed.
When opening a HTML file it also show's the JSHint toolbox below. The original JSLint extension does not.
Can you turn that off? Or maybe it is configurable?
I've updated Brackets to the latest master version and now JSLint is used instead of JSHint.
How can I switch back to JSHint?
Thanks.
Would you mind pulling in 2.5.4 and publishing? There are some nice fixes, and a new global.
I am thinking that it would be nice to have this extension operate in a similar manner to the JSLint extension with the auto collapse of the panel when no issues are found. If I figured out how to do so, would you accept a pull request?
First off, I love your plugin (so nice to use this instead of JSLint) 👍
My folder structure is:
When I place my .jshintrc
file into each project folder it works perfectly. However, when I move it into my Sites
folder it stops working, giving me these errors:
This seems to not match the behavior described in the JSHint docs:
In case of .jshintrc, JSHint will start looking for this file in the
same directory as the file that's being linted. If not found, it will
move one level up the directory tree all the way up to the filesystem
root.
I'd like to have just one .jshintrc
file in the parent Sites
folder that each project folder reads. Is this possible?
Thank you :)
Hey,
JSHint always complains about '[variable-name] used out of scope' when I define a variable with 'var' in an if or loop block and then use it outside the block like this:
if(a == b){
var x= 'test';
}else{
var x= 'big string with text';
}
console.log(x);
This behavior is wrong because the scope for variables defined with var only changes in function blocks.
Hope you can fix this, it is relay annoying.
I use Brackets to develop with Meteor, which has a file watcher and automatically restarts the server when it detects that project files have been updated. When I save .js
files in order to JSHint them, that causes an artificial restart of the server.
Any way to run JSHint without saving the .js
file? Maybe by saving to a temporary file?
i use a shebang on my first code line for server scripts, as it is legal with node.js.
#!/usr/bin/env node
jslint in brackets moans about them and stops linting. please fix it.
It's good that .jshintrc files now don't have to be in the project root, but when I try to place one in a subfolder, that becomes the only file used. Could we change this to match the behaviour of the JSHint CLI, which implements this sort of thing (jshint/jshint#1314)?
JSLint don't recognize that 'window' (window.navigator.userAgent;) is a global variable, and display a warning like this:
'window' is not defined. (W117)
/*global window */
will supress this warning, but it should know that is a global.
Before Brackets 1.1, I think the JSHint extension automatically suppressed JSLint errors. In 1.1, with the new multiple linter support, JSLint errors started showing up again. It might be good to put a note in your README about adding the proper preference to .brackets.json
to re-suppress the JSLint errors:
"language": {
"javascript": {
"linting.prefer": "JSHint",
"linting.usePreferredOnly": true
}
}
Or maybe there's a way you could set that preference programmatically by default (though you'd have to make sure that the user's own .brackets.json
would properly override that).
I am doing meteor dev and looking to try jshint with brackets. Instructions state "To install, place in your brackets/src/extensions/user folder." Brackets install was from the .msi and I do not find any such location. How do I install jshint?
I don't see this plugin doing anything whatsoever. No new main menu items as far as I could find, no new context menu items, and my assumption that JS files are hinted on save was apparently wrong too. So I can't work out how make this plugin go...
Could you explain (on the project front page preferrably) how to work this plugin?
Hello,
I got an issue where when I clicked on "Enable JsHint" nothing happened. I looked a little and it appears LanguageManager.getLanguageForPath(fileEntry) failed to return javascript for my file (the name was : footer.js).
I hardcoded "javascript" as default language as a quick fix, but i guess i'm not alone in this case.
Anyway, great work.
Christian
Is it possibile to hint JS code inside a JSP file?
Thank you!!!
GIven as structure
/ (project root)
/assets
/.jshintrc
/components
/dashboard.js
/tests
/.jshintrc
/components
/dashboard.js
The .jshintrc
files are not being loaded in Brackets-JSHint extension.
...In case of .jshintrc, JSHint will start looking for this file in the same directory as the file that's being linted. If not found, it will move one level up the directory tree all the way up to the filesystem root.
JSHint supports config info set in the jshintConfing
property of package.json
. Would be nifty if Brackets supported that too.
More details here (scroll down to "Configuration").
brackets-jshint extension ignores the jshint options
when parsing the currently opened script.
JSHint docs current state:
"In case of .jshintrc, JSHint will look for this file in the current working directory and, if not found, will move one level up the directory tree all the way up to the filesystem root. (Note that if the input comes from stdin, JSHint doesn't attempt to find a configuration file)"
However, brackets-jshint currently only scans the project root directory for this file.
Can we update the extension to behave the way JSHint was designed?
In addition to .jshintrc
, there's a .jshintignore
file that can be used to exclude files or folders. It would be nice if this extension also ignored those files and didn't pop up the errors panel when you open one. Especially useful if you're pairing it with a bulk-linting extension like my Lint All the Things.
There are basically no official docs on the file format that I could find. This forum post is the closest thing: https://groups.google.com/d/msg/jshint/62N12QUhBCs/v9a1XC7I_j8J. So it looks like just a list of standard globs (Brackets includes a globmatch library that you can probably use for this).
In the latest version, 2.2.16, I get this error for every file that I try to lint. Reverting back to 2.2.15 lints all of the same files just fine (and super quickly).
Running in the following Brackets version: Release 1.3 build 1.3.0-16022 (release cd0a6aae5)
Hi,
since I updated brackets to 0.44 whn I save a js file brackets freezes for a while and tells me JSHint has reached ist timeout ...
"JSHint hat die Zeitbegrenzung von 10000 ms überschritten "
Any idea what to do or where to look ?
Regards
Karsten
Sprint 44 Experimenteller Build 0.44.0-14876 (release 6d2d33d80)
Hey cfjedimaster,
I recently created a clone of brackets-jshint to add support for React.js JSX files (https://github.com/globexdesigns/brackets-jsxhint). The code is almost identical to brackets-jshint, but with with 10 new lines and React.js' JSXTransformer.js file. Which leads me to wonder... would it be better if I created a pull request here to merge that feature in? Or should your extension only focus on Javascript files?
I'm a little torn, because having a bunch of very similar linting extensions in Brackets feels frustrating to users and difficult to maintain for developers, but on the other hard, having JSX support in a JSHint extension might be beyond its original intent.
What do you think?
I use 'sprint 42 experimental build'. I've tried to put .jshintrc inside my root/js, root(even both together) folder of my project and jshint doesn't apply my configuration:
{
"curly": true,
"eqeqeq": true,
"eqnull": true,
"expr": true,
"latedef": true,
"newcap": true,
"onevar": true,
"noarg": true,
"node": true,
"trailing": true,
"undef": true,
"strict": true,
"unused": true,
"trailing": true
}
After double-clicking on a warning, the cursor lands one character to the right of where the troublesome statement starts. Example:
console.log('food'); console.log('bar');
The cursor will be under 'o', not under 'c'.
I have a JS file that's an array of arrays used for games that need a dictionary. It's 1362KB in size, and upon loading it in Brackets, JSLint embarks on an epic journey to try to lint it.
Well, it doesn't need linting--just editing. Brackets hangs up like a jilted girlfriend during the lint; the current web version of JSHint eventually struggles through the file, but it takes a very long time.
Not your fault, for sure, but still an issue. An option for the plug-in that disallowed linting any file larger than X KB would likely resolve this and still allow linting files of a more sane size. Any JS file larger than 100K probably needs to be broken down into smaller modules. Unfortunately for the dictionary, breaking it down into smaller files isn't really an option.
The jsHint toggle panel could contain two tabs, one for the "problems", and the other for "unused".
This extension uses the NativeFileSystem.FileReader
API, which has been removed. In the next release of Brackets, the extension will crash when trying to read the file.
It should be straightforward to switch to an alternative such as the new File.read()
API or the existing FileUtils.readAsText()
API. You can release this update in advance if you want, since users of Brackets Sprint 33 (the current release) will still be able to install the older version of your extension that is compatible with their build.
See the migration guide and discussion thread for details.
As an user I would like to see support for a .jshintrc file so I can define all my JSHint rules on a project base level.
Is it possible in this current extension to implement?
hi, i have a .jshintrc in the project's root directory but it doesn't appear to get picked up by the extension.
i'm using Brackets 34 and the latest version of the extension (2.0.14).
if there's anything i can do to troubleshoot the issue, do let me know.
Can we somehow make JSHint skip minified blocks of code?
I make it a habit to put blocks of minified (third-party) code at the top of my main JS file, so I don't have to combine them before deploying. Mind you it's minified, not packed. But minified code oftenly starts with a semicolon, so maybe ignore such lines?
Having incorrect variables in the in the .jshintrc file currently cause errors to be thrown into the Brackets console and the Linting API to fail.
Here is an example .jshintrc that will cause an issue.
{
"foo": true
}
In this example, the failure occurs due to the incorrect "foo" variable. Brackets will report the error as: "Uncaught TypeError: Cannot read property 'length' of undefined". But looking into it further, the failure actually happens inside JSHint which states: "Bad option: 'foo'." as part of the "messageOb" variable in the extension.
Such errors should be reported back to the user in a friendly way without breaking the Brackets linting API.
Additionally, the "es5" option is also complaining - even though it's a valid JSHint option.
{
"es5": true
}
The response from JSHint is: ES5 option is now set per default.
I believe that should be handled as a warning and not cause bracket-jshint to break.
Brackets Sprint 31 will introduce a new, clean API for linting providers:
https://github.com/adobe/brackets/wiki/Release-Notes:-Sprint-31#newimproved-extensibility-apis
Using the new API could potentially improve the UI of this extension -- and allow it to benefit from future linting functionality upgrades automatically.
I know "white" is going to be deprecated soon, but from what I can see it hasn't been yet.
When using .jshintrc with "white:true" -- the rule isn't being used. However, if I remove .jshintrc from my project and add "/jshint white:true/" at the top of my file -- the rule is enabled.
How come there is this inconsistency? Any chance we can keep the rule enabled via .jshintrc?
Hello
I have a project which has a .jshintrc file at the root of the folder and i have a subfolder where i want a different jshint configuration, is it possible to look to use the .jshintrc file in current folder ?
attached screenshot shows my setup, the problem being the jshintrc file inside the src folder isn't used.
Instead of the big ol' screen popping up, how about marking the lines with exclamation marks next to the line number or different color?
This way, when you are in the mids of writing new things which are broken because they aren't finished yet, you wouldn't lose screen realestate & focus for the JSHint screen every time you save.
Something like this would bind the notifications better to the workflow - ie. get things together first, then clean up the linting/hinting problems. So, by definition, syntax errors etc. should be more visible than lint/hint errors. By changing them to something less visible, the human brain sorts out the priority by itself. :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.