编写 CoffeeScript 时有没有办法捕捉错别字

2022-01-24 00:00:00 javascript coffeescript jslint

这个小的 CoffeeScript 包含一个错字

This small CoffeeScript contains a typo

drinks = "Coffee"
drinks = drinks + ", " + "Tea"
drinsk = drinks + ", " + "Lemonade"
alert drinks

本意是提醒咖啡、茶、柠檬水",但结果却是咖啡、茶".生成的 JavaScript 仍然有效并通过 JSLint;它在使用前声明变量很好,但它的变量错误.

The intention was to alert "Coffee, Tea, Lemonade" but the result is instead "Coffee, Tea". The generated JavaScript is still valid and passes JSLint; it declares the variables before usage which is good, but its the wrong variables.

var drinks, drinsk;
drinks = "Coffee";
drinks = drinks + ", " + "Tea";
drinsk = drinks + ", " + "Lemonade";
alert(drinks);

如果同样的例子是用纯 JavaScript 编写的,那么 JSLint 会捕捉到错误:

If the same example was written in plain JavaScript then JSLint would catch the error:

var drinks;
drinks = "Coffee";
drinks = drinks + ", " + "Tea";
drinsk = drinks + ", " + "Lemonade";
alert(drinks);

------------------
Problem at line 4 character 1: 'drinsk' was used before it was defined.
drinsk = drinks + ", " + "Lemonade";

问题:有没有办法保留我犯的错误以便我找到它们?我希望看到像 JSLint 这样的工具仍然有效.

To the question: Is there a way to keep the errors I make so that I can find them? I would love to see tools like JSLint still work.

也试过 http://www.coffeelint.org/ 它告诉我你的代码是 lint免费!"

Also tried http://www.coffeelint.org/ and it tells me "Your code is lint free!"

推荐答案

您可以使用支持标识符拼写检查的IDE,例如IntelliJ IDEA,顺便说一句,它有一个用于CoffeScript编辑的插件.

You can use IDE which supports identifier spellchecking, for example, IntelliJ IDEA which BTW has a plugin for CoffeScript editing.

相关文章