jslint

Javascript Regex to specify what is allowed (rather than what is not)

岁酱吖の 提交于 2020-01-13 12:07:23
问题 I've been using this: str2 = str1.replace(/[^\w]/gi, ''); It works fine, but falls foul of JSLint for having an insecure '^' as outlined in the posts here and here. The consensus is that it is better to use your regex to specify what is allowed rather than what is not. No one ever demonstrates how to do this, however. I've even got Flanagan and Crockford in front of me here, but to my shame I'm still not sure what to do. So... how do you set str2 to only allow the \w characters found in str1

Javascript Regex to specify what is allowed (rather than what is not)

寵の児 提交于 2020-01-13 12:06:47
问题 I've been using this: str2 = str1.replace(/[^\w]/gi, ''); It works fine, but falls foul of JSLint for having an insecure '^' as outlined in the posts here and here. The consensus is that it is better to use your regex to specify what is allowed rather than what is not. No one ever demonstrates how to do this, however. I've even got Flanagan and Crockford in front of me here, but to my shame I'm still not sure what to do. So... how do you set str2 to only allow the \w characters found in str1

is it possible to run JSLint as commandline in windows with help of node.js?

随声附和 提交于 2020-01-12 14:57:09
问题 I mean to run it like this: node.exe lint.js my_js_file.js And then get output to a console. What do I need to download ? Do I need just to save http://www.jslint.com/ to disk and then grab some attached js file or I need to look for special version for node.js ? 回答1: Install jshint globally then you can use it from the command line. npm install -g jshint jshint testfile.js All this is assuming that you already have node and npm running on you windows machine. Edit I just noticed that I

Why does JSLint forbid the “this” keyword?

独自空忆成欢 提交于 2020-01-10 04:10:42
问题 Consider this simple example: "use strict"; var Foo = { field: 0, func: function () { this.field = 4; } } JSLint throws the error: Unexpected 'this'. At the line "this.field = 4". I've seem some questions here in StackOverflow asking for this, and in all the cases, the answer was just to enable the "Tolerate this" flag. However, I'm interested in why do the JSLint creators think the use of "this" is (or might lead to) an error. Also, how would I implement member functions without the "this"

什么是“Linting”?

梦想与她 提交于 2020-01-06 20:53:37
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> PHPLint,JSLint和我最近遇到了“你可以动态地抓取你的JS代码”,同时阅读有关某些IDE的内容。 那么,这是什么 掉毛 人人都知道,而我呢? #1楼 lint是一个用于标记源代码的工具,带有一些可疑和非结构(可能导致bug)。 它是C语言中的静态代码分析工具。现在它成为用于描述标记可疑代码的软件分析工具的通用术语。 #2楼 Linting 是检查Programmatic和Stylistic错误的源代码的过程。 这有助于识别编码过程中出现的一些常见和不常见的错误。 Lint 或 Linter 是一个支持linting(验证代码质量)的程序。 它们适用于大多数语言,如JavaScript,CSS,HTML,Python等。 一些有用的棉绒是 JSLint的 , CSSLint , JSHint , pylint的 #3楼 除了别人提到的内容外,我想补充一点,Linting将通过您的源代码查找 - formatting discrepancy - non-adherence to coding standards and conventions - pinpointing possible logical errors in your program 在源代码上运行Lint程序有助于确保源代码易读,易读

JS: How to fix “Expected ')' to match '(' from line 4 and instead saw '='.” JSLint error

[亡魂溺海] 提交于 2020-01-05 08:45:09
问题 I have written the following function: function MyTest(element, no, start=0) { this.no = no; this.element = element; this.currentSlide = start; self.start(); } JSLint complains: Expected ')' to match '(' from line 4 and instead saw '='. What is wrong with this? Is it the default value I've set? 回答1: JavaScript doesn't have default values for arguments (yet; it will in the next version, and as Boldewyn points out in a comment, Firefox's engine is already there), so the =0 after start is

How do I stop visual studio inserting a space between function definition and immediate call?

点点圈 提交于 2020-01-03 07:22:28
问题 I am using the visual studio JSLint plugin to keep my javascript in order, which seems to work really well apart from this one problem. If I type in x = (function () { }()) And then put the semicolon on the end, Visual studio corrects it to: x = (function () { } ()); And then JSLint complains JS Lint: Unexpected space between '}' and '('. Obviously this is fixable by removing the space, but visual studio is very persistent in putting the space back. Putting a semicolon anywhere inside the

WHY JSLint complains: “someFunction() was used before it was defined”?

不打扰是莪最后的温柔 提交于 2020-01-02 04:36:04
问题 Searching for the JSLint error "was used before it was defined" i've found these: JSLint: Using a function before it's defined error Function was used before it was defined - JSLint JSLint: was used before it was defined jsLint error: “somefunction() was used before it was defined” jslint - Should we tolerate misordered definitions? Problem None of those answers WHY the error is shown. Elaboration According to the ECMA-262 Specification functions are evaluated before execution starts, hence

Why using a source tag inside an audio tag prevents the loadeddata event from firing?

ぃ、小莉子 提交于 2020-01-01 09:54:26
问题 For better accessibility we needed a second alternative set of play/pause controls and (with the help of user Kento Nishi) we successfully moved from DEMO A (with only 1 audio playback control) to DEMO B (with duplicated audio playback controls). PROBLEM1 The time duration (far right number) is broken in DEMO B. PROBLEM2 Every webpage has its own folder. Some pages have a spoken audio file ready made, *.mp3 but some pages dont. Would it be possible to hide all audio controls html if the

Why does JSLint give strict violation error on this function?

∥☆過路亽.° 提交于 2020-01-01 09:33:13
问题 JSLint gives me the "strict violation" error, although I use the "this" context inside a function which hides it from the global scope. function test() { "use strict"; this.a = "b"; } For the record, I use the built-in JSLint parser in Webstorm. 回答1: This is because JSLint doesn't recognize your function as a constructor. By convention, you must use uppercase letters. function Test() { "use strict"; this.a = "b"; } 来源: https://stackoverflow.com/questions/17770048/why-does-jslint-give-strict