简体   繁体   English

如何在 Vue 中使用 ESLint 规则在脚本标签中强制执行 lang="ts"

[英]How to enforce lang="ts" in script tags with an ESLint rule in Vue

I'm looking for a way to enforce that everyone working on our code base use TypeScript for Single File Components.我正在寻找一种方法来强制执行我们代码库的每个人都将 TypeScript 用于单文件组件。 All the components use TypeScript, so disabling JavaScript is also an option.所有组件都使用 TypeScript,因此禁用 JavaScript 也是一种选择。

I thought that this could be done with an ESLint rule, but I can't find it.我认为这可以通过 ESLint 规则来完成,但我找不到。

This feature is now available in eslint-plugin-vue .此功能现在在eslint-plugin-vue中可用。 Use the vue/block-lang rule.使用vue/block-lang规则。

// .eslintrc.json
{
  "vue/block-lang": ["error",
    {
      "script": {
        "lang": "ts"
      }
    }
  ]
}

https://eslint.vuejs.org/rules/block-lang.html#vue-block-lang https://eslint.vuejs.org/rules/block-lang.html#vue-block-lang

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Nuxt Vue Typescript 全局插件在脚本语言 ts 中不可用 - Nuxt Vue Typescript global plugins unavailable inside script lang ts 是否有针对 TypeScript 错误 TS2345 的 eslint 规则 - Is there an eslint rule for TypeScript error TS2345 如何使用 ts-standard 禁用整个 TypeScript 项目的 ESLint 规则? - How to disable ESLint rule for whole TypeScript project using ts-standard? eslint 规则强制 Typescript 可选参数函数语法 - eslint rule to enforce Typescript optional parameter function syntax ESLint、TypeScript、Vue 和 WebPack Encore:无法禁用 ESLint 规则 - ESLint, TypeScript, Vue and WebPack Encore: Cannot disable ESLint rule 将查询选择器结果转换为 vue 组件内的 HTMLElement 时出现编译错误<script lang="ts"> code - Compilation error on casting query selector result to HTMLElement inside a vue component's <script lang="ts"> code 使用 TypeScript 设置时,Vue 3 模板中的 ref() 出现掉毛错误<setup lang="ts" script></setup> - Linting errors for ref()'s within Vue 3 templates when using setup with TypeScript <setup lang="ts" script> 如何让 ESLint 只处理 process.ts 文件? - How to get ESLint to only process .ts files? 如何覆盖此ESLint TypeScript规则? - How do I override this ESLint TypeScript rule? 如何在 typescript eslint 中强制执行文件名和文件夹名称约定? - How can I enforce filename and folder name convention in typescript eslint?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM