jslint

JavaScript开发工具大全

有些话、适合烂在心里 提交于 2019-12-22 21:01:02
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 译者按: 最全的JavaScript开发工具列表,总有一款适合你! 原文: THE ULTIMATE LIST OF JAVASCRIPT TOOLS 译者: Fundebug 为了保证可读性,本文采用意译而非直译。另外,本文版权归原作者所有,翻译仅用于学习。 简介 2017年1月,Stack Overflow年度开发者调研一共访问了64000个程序员,发现JavaScript已经连续5年成为最流行的编程语言。 这篇博客将介绍一些常用的JavaScript开发工具: 构建&自动化 · IDE&编辑器 · 文档 · 测试 · 调试 · 安全 · 代码优化&分析 · 包管理 ##构建 & 自动化 Webpack对JavaScript应用依赖的所有模块进行静态分析,生成依赖图,然后将它们打包成数个静态文件。 Grunt以将重复耗时的任务自动化。Grunt的生态系统非常大,有超过6010个插件。 Gulp发布于Grunt之后,采用了完全不同的方式,使用JavaScript函数定义任务。它有超过2770个插件,并且提供了更好的控制。 Browserify使得开发者可以在浏览器使用CommonJS模块。开发者像在node环境一样,通过require('modules')来组织模块之间的引用和依赖

Wrapping For in loops with if statements in Javascript — looping over arrays

大兔子大兔子 提交于 2019-12-22 04:35:14
问题 JSLint keeps complaining about things like this var myArray = [1, 2, 3]; for (var value in myArray) { // BLAH } Saying that I should wrap it in an if statement. I realize you need to wrap it if you are looping over an object's properties, but here what should I put in the if statement to do the correct filtering. Additionally when I do something like for (var i = 0; i < 10; i++) { // foo } for (var i =0; i < 20; i++) { // bar } It complains that i has already been defined. How do I prevent

JSLint error: Move the invocation into the parens that contain the function

别来无恙 提交于 2019-12-21 21:23:04
问题 How can i make this code jsLint Happy ? ;(function ( $, window, document, undefined ) { //some code })( jQuery, window, document ); It advises me to write it this way ? Will there be any difference ? What do i do ? (function ( $, window, document, undefined ) { //some code }( jQuery, window, document )); 回答1: I'm copying my answer from the next question in the JSLint stack. Here's why Crockford says that the second way is better. From http://javascript.crockford.com/code.html When a function

如何在JavaScript中将字符串编码为Base64?

橙三吉。 提交于 2019-12-21 17:00:46
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 我有一个PHP脚本,可以将PNG图像编码为Base64字符串。 我想使用JavaScript做同样的事情。 我知道如何打开文件,但不确定如何进行编码。 我不习惯使用二进制数据。 #1楼 我+1了Sunny的答案,但我想回馈我为自己的项目所做的一些更改,以防有人发现它有用。 基本上,我只是对原始代码进行了一点清理,因此JSLint不会抱怨太多,因此我将注释中标记为私有的方法实际上设为私有。 我还添加了我自己的项目中需要的两种方法,即 decodeToHex 和 encodeFromHex 。 编码: var Base64 = (function() { "use strict"; var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; var _utf8_encode = function (string) { var utftext = "", c, n; string = string.replace(/\r\n/g,"\n"); for (n = 0; n < string.length; n++) { c = string.charCodeAt(n); if (c < 128) { utftext

Why does jslint complain when I escape the < character in a RegEx?

安稳与你 提交于 2019-12-21 15:17:33
问题 The code: var foo = /\</; When I go to jslint.com and enter that in, I get: Problem at line 1 character 12: Unexpected '\'. It used to tell me Unexpected escaped character '<' in regular expression. but times have changed. So I'm just curious, why? If you try var foo = /\>/; it doesn't care, what's the deal with < ? 回答1: If you have a two simple divs, the difference is clear: <div> < </div> <!--Missing right angle bracket, bad markup--> <div> > </div> <!--No problem, just a greater than text

Suppress `Expected an identifier and instead saw 'default' (a reserved word)` in JSLint with Mongoose

心不动则不痛 提交于 2019-12-21 12:44:37
问题 I'm using jshint to validate my JavaScript files. On the server-side I'm using node.js with Mongoose. In Mongoose I'm encouraged to write schemata in a fashion like: var UserSchema = new mongoose.Schema({ firstname : { type: String, default: '' } }); When running linting, I get error: Expected an identifier and instead saw 'default' (a reserved word). Is there a way to suppress this error? I really would prefer that behaviour instead of writing: var UserSchema = new mongoose.Schema({

Contending with JS “used before defined” and Titanium Developer

人走茶凉 提交于 2019-12-21 03:55:12
问题 I have a lengthy JavaScript file that passes JSLint except for "used before it was defined" errors. I used normal function declarations, as in... function whatever() {do something;} as opposed to... var whatever = function(){do something;}; and consistent with Steve Harrison's reply to an earlier post... Assuming you declare all your functions with the function keyword, I think it becomes a programming-style question. Personally, I prefer to structure my functions in a way that seems logical

Pre Commit Hook for JSLint in Mercurial and Git

久未见 提交于 2019-12-20 11:48:19
问题 I want to run JSLint before a commit into either a Mercurial or Git repo is done. I want this as an automatic step that is set up instead of relying on the developer (mainly me) remembering to run JSLint before-hand. I normally run JSLint while developing, but want to specify a contract on JS files that they pass JSLint before being committed to the repo. For Mercurial, this page spells out the precommit syntax, but the only variables that seem to be available are the parent1 and parent2

Can JSLint be configured using an external config file in the same manner as JSHint's .jshintrc?

筅森魡賤 提交于 2019-12-20 03:33:28
问题 I've been developing a lot of small web development projects in various IDEs, and find myself laboriously typing in jslint configuration headers to silence JSLint. Its warnings and errors are all valid, and I want to keep JSLint in my work cycle, but I spin up 2-3 isolated environments a day, sometimes from generators in Yeoman, other times by hand. These all end up with gripes from JSLint that require the following in every .js file: /*jslint browser:true*/ /*global require,yada,yada,yada*/

JSLint “out of scope” error due to function ordering?

 ̄綄美尐妖づ 提交于 2019-12-19 18:57:10
问题 JSLint seems to be picky about function ordering. This passes fine: function a() { 'use strict'; return 1; } function b() { 'use strict'; a(); } While this gives an 'a' is out of scope error message: function b() { 'use strict'; a(); } function a() { 'use strict'; return 1; } Is this by design? Should I care? How can it be avoided in larger (more complex) cases, where it might not always be possible to give the functions a clear order? 回答1: JSLint/JSHint expect you to define functions before