如何忽略tslint的特定目录或文件?

时间:2016-01-03 16:16:33

标签: javascript ide typescript webstorm tslint

正在使用的IDE是WebStorm 11.0.3,tslint已配置并可以正常工作,但是,它会挂起,因为它会尝试解析大型* .d.ts库文件。

有没有办法忽略特定的文件或目录?

10 个答案:

答案 0 :(得分:142)

更新使用TSLINT v5.8.0

正如Saugat Acharya所述,您现在可以更新 tslint.json CLI选项:

{
  "extends": "tslint:latest",
  "linterOptions": {
      "exclude": [
          "bin",
          "lib/*generated.js"
      ]
  }
}

更多信息here

TSLINT 3.6

引入了此功能
tslint \"src/**/*.ts\" -e \"**/__test__/**\"

您现在可以添加--exclude(或-e),在此处查看PR

<强> CLI

usage: tslint [options] file ...

Options:

-c, --config          configuration file
--force               return status code 0 even if there are lint errors
-h, --help            display detailed help
-i, --init            generate a tslint.json config file in the current working directory
-o, --out             output file
-r, --rules-dir       rules directory
-s, --formatters-dir  formatters directory
-e, --exclude         exclude globs from path expansion
-t, --format          output format (prose, json, verbose, pmd, msbuild, checkstyle)  [default: "prose"]
--test                test that tslint produces the correct output for the specified directory
-v, --version         current version

您正在使用

-e, --exclude         exclude globs from path expansion

答案 1 :(得分:25)

我正在使用Visual Studio Code和此

/* tslint:disable */

为我工作。看看这个页面,大约有3/4的路程有一些禁用命令https://c9.io/lijunle/tslint

需要注意的事项。上面的禁用禁用该页面上的所有tslint规则。如果要在页面中间禁用特定规则,则会有一系列规则。所以你可以关掉特定的东西,比如

/* tslint:disable comment-format */

答案 2 :(得分:23)

除了迈克尔的回答,请考虑第二种方法:将linterOptions.exclude添加到tslint.json

例如,您可能会tslint.json包含以下行:

{
  "linterOptions": {
    "exclude": [
      "someDirectory/*.d.ts"
    ]
  }
}

答案 3 :(得分:11)

tslint v5.8.0开始,您可以在exclude文件的linterOptions密钥下设置tslint.json媒体资源:

{
  "extends": "tslint:latest",
  "linterOptions": {
      "exclude": [
          "bin",
          "**/__test__",
          "lib/*generated.js"
      ]
  }
}

有关此here的更多信息。

答案 4 :(得分:9)

遇到问题的are others。不幸的是,排除文件只有一个未解决的问题:https://github.com/palantir/tslint/issues/73

所以我担心答案是否定的。

答案 5 :(得分:3)

我必须使用** / *语法排除文件夹中的文件:

    "linterOptions": {
        "exclude": [
          "src/auto-generated/**/*",
          "src/app/auto-generated/**/*"
        ]
    },

答案 6 :(得分:1)

linterOptions当前仅由CLI处理。 如果不使用CLI,则根据所使用的代码库,您需要在其他位置设置忽略。 webpack,tsconfig等

答案 7 :(得分:1)

可以通过在package.json中通过定义exclude参数修改lint脚本来确认在tslint 5.11.0版本上是否可以正常工作

@login_required
def ProfileUpdateView(request):
    if request.method == 'POST':
        user_form = accounts_forms.UserUpdateForm(request.POST, instance=request.user)
        if request.user.is_staff == True:
            profile_form = accounts_forms.StaffProfileUpdateForm(
                request.POST, instance=request.user.staffprofile)
        else:
            profile_form = accounts_forms.StudentProfileUpdateForm(
                request.POST, instance=request.user.studentprofile)

        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()

            log = LogEntry.objects.log_action(
                user_id=request.user.id,
                content_type_id=ContentType.objects.get_for_model(user).pk,
                object_id=repr(user.id),
                object_repr=str(user.username),
                action_flag=CHANGE,
                change_message = 'IM STUCK HERE',)

                log.save()

            messages.success(request, 'Your profile has been updated.')
            return redirect('update-profile')

    else:
        user_form = accounts_forms.UserUpdateForm(instance=request.user)
        if request.user.is_staff == True:
            profile_form = accounts_forms.StaffProfileUpdateForm(instance=request.user.staffprofile)
        else:
            profile_form = accounts_forms.StudentProfileUpdateForm(
                instance=request.user.studentprofile)
    context = {
        'user_form': user_form,
        'profile_form': profile_form,
    }
    return render(request, 'accounts/update_profile.html', context)

干杯!

答案 8 :(得分:1)

作为补充

要禁用下一行的所有规则 // tslint:disable-next-line

要为下一行禁用特定规则// tslint:disable-next-line:rule1 rule2...

要禁用当前行的所有规则someCode(); // tslint:disable-line

要为当前行禁用特定规则someCode(); // tslint:disable-line:rule1

答案 9 :(得分:1)

在您的代码示例中添加该部分

"linterOptions": {
"exclude": [
  "node_modules/**/*.",
  "db/**/*.",
  "integrations/**/*."
]

},