如何在 Visual Studio 2017 中禁用 JavaScript 构建错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42724820/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 01:23:49  来源:igfitidea点击:

How to disable JavaScript build error in Visual Studio 2017?

javascriptvisual-studiovisual-studio-2017eslint

提问by Mohammad Dayyan

I just updated Visual Studio 2017 from RC to final. I didn't get the following error but recently I get this error. In building the project, I get the following error and it prevents the web project to start:

我刚刚将 Visual Studio 2017 从 RC 更新为最终版本。我没有收到以下错误,但最近我收到了这个错误。在构建项目时,我收到以下错误并阻止 Web 项目启动:

Severity    Code    Description Project File    Line    Suppression State
Error   eqeqeq  (ESLint) Expected '===' and instead saw '=='.   VistaBest.Shop.Web  C:\***\Request.js   21

JavaScript Error

JavaScript 错误

How can I disable JavaScript building error in Visual Studio 2017?

如何在 Visual Studio 2017 中禁用 JavaScript 构建错误?

回答by Mohammad Dayyan

I think, find the solution:

我想,找到解决办法:

  1. Open Tools > Options
  2. Navigate to Text Editor > JavaScript/TypeScript > EsLint(in VS2017 15.8 it is Lintingnot EsLint)
  3. Set Enable ESLintto False
  1. 打开 Tools > Options
  2. 导航到Text Editor > JavaScript/TypeScript > EsLint(在 VS2017 15.8 中Linting不是EsLint
  3. 设置Enable ESLintFalse

Disable ESlint

禁用 ESlint

Visual Studio >= 15.8.5 Disable ESlint Visual Studio 15.8.5

Visual Studio >= 15.8.5 禁用 ESlint Visual Studio 15.8.5

回答by Brad

In Visual Studio 2017 (v 15.8.0):

在 Visual Studio 2017 (v 15.8.0) 中:

Option 1: Options > JS Errors

选项 1:选项 > JS 错误

  1. Open Tools > Options
  2. Navigate to Text Editor > JavaScript/TypeScript > Code Validation
  3. Set Enable JavaScript errorsto false
  4. or, set Enable JavaScript errorsto trueand Show errors as warningsto true
  1. 打开 Tools > Options
  2. 导航 Text Editor > JavaScript/TypeScript > Code Validation
  3. 设置Enable JavaScript errorsfalse
  4. 或者,设置Enable JavaScript errorstrueShow errors as warningstrue

I needed to restart Visual Studio for this to take effect.

我需要重新启动 Visual Studio 才能生效。

Options >JS Errors

选项 >JS 错误

Option 2: Options > Linting

选项 2:选项 > Linting

There is another option below which will let you edit your global linting settings:

下面还有另一个选项可让您编辑全局 linting 设置:

Options >JS Linting

选项 >JS Linting

Option 3: .eslint file

选项 3:.eslint 文件

You can also create a file named .eslintrcin the root of your project.

您还可以创建一个.eslintrc在项目根目录中命名的文件。

Option 4: ESLint commands in-file

选项 4:文件中的 ESLint 命令

See @user9153924's answer

见@user9153924 的回答



Resources

资源

回答by Rafael dos Santos

I tried Mohammad`s solution but it didn't work. I managed to work doing the following:

我尝试了穆罕默德的解决方案,但没有奏效。我设法完成了以下工作:

  1. Righ click on your web .csproj file
  2. On the first <PropertyGroup>add the following entry: <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
  1. 右键单击您的 Web .csproj 文件
  2. 在第一个<PropertyGroup>添加以下条目: <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>

回答by user9153924

Add /*eslint eqeqeq: ["error", "smart"]*/to the first line of your Javascript code to remove the errors. https://eslint.org/docs/rules/eqeqeq

添加/*eslint eqeqeq: ["error", "smart"]*/到您的 Javascript 代码的第一行以删除错误。 https://eslint.org/docs/rules/eqeqeq

Following Mohammad's solution will turn off ESLint for syntax checking. This works in VS2015 and should work in later versions.

遵循 Mohammad 的解决方案将关闭 ESLint 进行语法检查。这适用于 VS2015,应该适用于更高版本。

回答by Nilachal Sethi

For Visual Studio 2019.

对于 Visual Studio 2019。

enter image description here

在此处输入图片说明

  1. Open Tools > Options
  2. Navigate to Text Editor > JavaScript/TypeScript
  3. => Linting > General.
  1. 打开工具 > 选项
  2. 导航到文本编辑器 > JavaScript/TypeScript
  3. => Linting > 一般。

Then unchecked ESLint check box. Please The bellow Image for reference.

然后取消选中 ESLint 复选框。请参考下图。

enter image description here

在此处输入图片说明

回答by cjl

I've just had to change the "eqeqeq"rule behaviour to include "smart":

我只需要更改“eqeqeq”规则行为以包含“smart”:

Edit the .eslintrc file found in your user root folder mentioned in other answers already.

编辑在其他答案中提到的用户根文件夹中找到的 .eslintrc 文件。

The change is made to the rulessection by adding the smart rule

通过添加智能规则对规则部分进行了更改

    "rules": {

    "eqeqeq": [2, "smart"],

Copied from the web article:This option enforces the use of === and !== except for these cases:

复制自网络文章:此选项强制使用 === 和 !== 除了这些情况:

  1. Comparing two literal values
  2. Evaluating the value of typeof
  3. Comparing against null
  1. 比较两个文字值
  2. 评估 typeof 的值
  3. 与 null 比较

I found the specifics at: https://eslint.org/docs/2.0.0/rules/eqeqeq

我在以下位置找到了详细信息:https: //eslint.org/docs/2.0.0/rules/eqeqeq

回答by SilentCoder

I tried Mohammad's solution but with no luck, I followed Rafeel answer and instead of adding his suggested code sample I removed below code from web .csprojand finally I was able to build and run my project. There were two places where you should remove that in the same file. Still, I don't have any clue how the removed code will affect my solution.

我尝试了 Mohammad 的解决方案,但没有运气,我遵循了 Rafeel 的回答,而不是添加他建议的代码示例,而是从中删除了以下代码web .csproj,最后我能够构建和运行我的项目。有两个地方你应该在同一个文件中删除它。不过,我不知道删除的代码将如何影响我的解决方案。

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props')" />

Hope this will also help someone to save the day..!!!

希望这也能帮助某人挽救这一天..!!!