文档管理中心
我的
工具开发工具DevEco Studio(Windows/macOS版)编写与调试应用代码编辑代码检查Code Linter代码检查规则通用规则@typescript-eslint@typescript-eslint/quotes

@typescript-eslint/quotes

强制使用一致的反引号、双引号或单引号风格。

说明
  • 该规则默认检查字符串是否正确使用双引号。如需修改请参考选项。
  • 该规则建议在对.ts文件进行检查时使用。如需检查.ets文件,建议使用@hw-stylistic/quotes。

规则配置

收起
自动换行
深色代码主题
复制
  1. // code-linter.json5
  2. {
  3. "rules": {
  4. "@typescript-eslint/quotes": "error"
  5. }
  6. }

选项

详情请参考@typescript-eslint/quotes选项。

正例

收起
自动换行
深色代码主题
复制
  1. export const double = "double";
  2. export const foo = `back
  3. tick`; // backticks are allowed due to newline

反例

收起
自动换行
深色代码主题
复制
  1. // 默认推荐使用双引号
  2. export const single = 'single';
  3. export const unescaped = 'a string containing "double" quotes';
  4. export const backtick = `back\ntick`; // you can use \n in single or double quoted strings

规则集

收起
自动换行
深色代码主题
复制
  1. plugin:@typescript-eslint/all

Code Linter代码检查规则的配置指导请参考Code Linter代码检查。