jshint

JavaScript : Expected and assignment or function call and instead saw an expression

只愿长相守 提交于 2021-02-19 06:07:40
问题 I am using JSHint to ensure my JavaScript is "strict" and I'm getting the following error: Expected an assignment or function call and instead saw an expression On the following code: var str = 'A=B|C=D' var data = {}; var strArr = str.split( '|' ); for (var i = 0; i < strArr.length; i++) { var a = strArr[i].split('='); a[1] && (data[a[0].toLowerCase()] = a[1]); // Warning from JSHint } Any ideas why I'm getting such an error or how I can code to remove the error. 回答1: Here is a simplified

Get warning when passing too few arguments to a javascript function

故事扮演 提交于 2021-02-07 10:10:17
问题 Is there a tool that can help me detect when a javascript function is being passed too few arguments? As far as I can tell, neither JSLint nor JSHint provides this feature. Just be make it clear, if I write: some_method = function(x,y) { // ..do stuff } some_method(2); I would like to be warned, that I might have to pass in another argument. 回答1: You can't do that, all parameters are always optional and you can pass an indefinite amount of parameters to a parameterless function (through the

Javascript ENUM pattern naming convention

点点圈 提交于 2021-02-06 09:46:11
问题 I am working on a javascript project which requires use of javascript "Enums" meaning Objects like: var WinnerEnum = { Player1: 1, Player2: 2, Draw: 0 }; This is working great for me, however, I have no idea what is the proper way (according to convention) to name the Enum because as far as I know only class names start with a capital letter (indicating the ability to call a constructor on). JSHint also outputs the following warning: Missing 'new' prefix when invoking a constructor. If there

ESlint: Turning off a specific rule across a project

为君一笑 提交于 2021-01-02 19:16:35
问题 I've read the docs on how to disable rules from within a file, however I'm wondering if there is a way to disable or overwrite rules from .eslintrc without overwriting other previous rules & presets I defined. I'm working in an AngularJS project so I used extends property inside my .eslintrc file. There are 3 specific rules from the angular ESlint plugin that I would like to disable, without disabling everything else I was using previously. Without the rules property all of my linting rules

Expected an identifier and instead saw '>'

冷暖自知 提交于 2020-12-04 02:18:12
问题 ReactDOM.render(<App />, document.getElementById('root')); Please let me know why VSCode [jshint] showed that issue? And please also let me know how to add some code inside .jshintrc 回答1: JSHint does not support linting of jsx . If you want to develop react applications using jsx you should disable it or better switch to ESLint. For Visual Studio Code there is a plugin that you can install. 回答2: Press ⇧⌘X and then write there jshint and uninstall it. After that write eslint and install it if

Expected an identifier and instead saw '>'

最后都变了- 提交于 2020-12-04 02:18:02
问题 ReactDOM.render(<App />, document.getElementById('root')); Please let me know why VSCode [jshint] showed that issue? And please also let me know how to add some code inside .jshintrc 回答1: JSHint does not support linting of jsx . If you want to develop react applications using jsx you should disable it or better switch to ESLint. For Visual Studio Code there is a plugin that you can install. 回答2: Press ⇧⌘X and then write there jshint and uninstall it. After that write eslint and install it if

前端科普系列(5):ESLint

跟風遠走 提交于 2020-10-30 19:51:29
作者:Morrain 【前端科普系列】帮助阅读者了解web前端,主要覆盖web前端的基础知识,但不深入讲解,定位为大而全并非细而精,适合非前端开发的同学对前端有一个系统的认识,能更好的与前端开发协作。尽可能的写成科普类文章,对于前端开发而言,只适合刚入门的新手。 本文为第五章,主要讲前端工程化中的很重要工具 ESLint,主要介绍 ESLint 的历史、用法以及如何基于ESLint 打造保护代码仓库优雅的护城河。 一、前言 战国时期强大的赵国想要一举攻打并吞并北边的燕国,而小国“梁城”位居两国之间,为战略要冲,是必取之地。于是赵国派遣大将巷淹中,率领十万大军攻打仅有四千人的“梁城”,梁城王向以守城著称的墨家求救。但梁城等到的却是一个其貌不扬、孤身应战的墨家侠客革离,谁料革离足智多谋,指挥梁城四千军民抵御十万赵军,功成身退。 (图片来源:网络) “梁城”就好比我们的项目仓库,“梁城”的秩序取决于“革离”有没有守好它!那我们的项目仓库呢? 你愿意看到城中杂乱无章、毫无规则、乱象丛生还是愿意看到城中秩序井然、风格统一、整齐有序?如何成为程序员里的“革离”,守好属于我们的天空之城? 二、关于 ESLint 1、ESLint 是什么 先来看下它在 官网 上的定义: Find and fix problems in your JavaScript code 没错就一句话, 发现并修复你

关闭特定行的eslint规则

二次信任 提交于 2020-08-14 15:07:38
问题: In order to turn off linting rule for a particular line in JSHint we use the following rule: 为了关闭JSHint中特定行的linting规则,我们使用以下规则: /* jshint ignore:start*/ $scope.someVar = ConstructorFunction(); /* jshint ignore:end */ I have been trying to locate the equivalent of the above for eslint. 我一直试图找到相当于以上的eslint。 解决方案: 参考一: https://stackoom.com/question/1sMPh/关闭特定行的eslint规则 参考二: https://oldbug.net/q/1sMPh/Turning-off-eslint-rule-for-a-specific-line 来源: oschina 链接: https://my.oschina.net/u/4438370/blog/4493919

快速发现bug ,用起来非常爽的七个神仙调试工具

怎甘沉沦 提交于 2020-08-10 05:49:05
接下来就好好介绍一下这七个开发调试工具,用起来是真的爽啊。建议收藏使用哦! Web浏览器中的开发工具 任何现代的 Web 浏览器都配有功能强大的工具来调试应用程序。 如使用控制台语句 cconsole.log() ,使用 alert() 的弹出窗口,还可以使用 debugger 语句暂停代码执行,这些对于我们的调试都很有帮助。 我们还可以使用网络检查器或CSS样式检查器让调试变得更轻松流畅。 任何现代网络浏览器都配备了强大的工具来帮助调试您的应用程序。它可以简单到使用console.log()的控制台语句,使用alert()的弹出窗口,甚至使用调试器语句暂停代码执行。这些工具对我们的调试任务非常有帮助,尤其是调试器语句。 Postman 地址: www.postman.com/ 几乎所有前端应用程序都发送和接收JSON响应和请求。 应用程序通过请求 API 可以做很多事情,例如身份验证,用户数据传输,甚至是一些简单的事情,例如获取所在位置的当前天气。 Postman 是调试接口的最佳工具之一。 它适用于 MacOS , Windows 和 Linux 的系统, 可以快速轻松地直接发送 REST , SOAP 和 GraphQL 请求。 使用 Postman,我们可以调整请求,分析响应和调试问题。 当不确定问题出在前端还是后端时,这是很有帮助的。 CSS Lint 地址: