From 249852a0d0b21fd152b9f04a55011ededc6a940e Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Fri, 11 Feb 2022 18:21:02 +0900 Subject: [PATCH] Add ignores option to no-unused-keys rule --- docs/rules/no-unused-keys.md | 2 + lib/rules/no-raw-text.ts | 24 +----- lib/rules/no-unused-keys.ts | 9 +++ lib/utils/regexp.ts | 20 +++++ tests/lib/rules/no-unused-keys.ts | 120 ++++++++++++++++++++++++++++++ 5 files changed, 152 insertions(+), 23 deletions(-) create mode 100644 lib/utils/regexp.ts diff --git a/docs/rules/no-unused-keys.md b/docs/rules/no-unused-keys.md index 491bcb37..2aea1705 100644 --- a/docs/rules/no-unused-keys.md +++ b/docs/rules/no-unused-keys.md @@ -159,6 +159,7 @@ i18n.t('hi') { "src": "./src", "extensions": [".js", ".vue"], + "ignores": [], "enableFix": false } ] @@ -167,6 +168,7 @@ i18n.t('hi') - `src`: specify the source codes directory to be able to lint. If you don't set any options, it set to `process.cwd()` as default. - `extensions`: an array to allow specified lintable target file extension. If you don't set any options, it set to `.js` and `.vue` as default. +- `ignores`: An array of key names and patterns to exclude from the check. If you want to specify a pattern, specify a string such as `/pattern/`. - `enableFix`: if `true`, enable automatically remove unused keys on `eslint --fix`. If you don't set any options, it set to `false` as default. (This is an experimental feature.) ## :couple: Related Rules diff --git a/lib/rules/no-raw-text.ts b/lib/rules/no-raw-text.ts index 4d2ac1a8..4c0f0582 100644 --- a/lib/rules/no-raw-text.ts +++ b/lib/rules/no-raw-text.ts @@ -25,6 +25,7 @@ import type { } from '../types' import { isKebabCase, pascalCase } from '../utils/casing' import { createRule } from '../utils/rule' +import { toRegExp } from '../utils/regexp' type LiteralValue = VAST.ESLintLiteral['value'] type StaticTemplateLiteral = VAST.ESLintTemplateLiteral & { @@ -54,32 +55,9 @@ function getFixQuote(quotes: Quotes, code: string) { } return null } -const RE_REGEXP_CHAR = /[\\^$.*+?()[\]{}|]/gu -const RE_HAS_REGEXP_CHAR = new RegExp(RE_REGEXP_CHAR.source) -const RE_REGEXP_STR = /^\/(.+)\/(.*)$/u -function toRegExp(str: string): RegExp { - const parts = RE_REGEXP_STR.exec(str) - if (parts) { - return new RegExp(parts[1], parts[2]) - } - return new RegExp(`^${escape(str)}$`) -} const hasOnlyWhitespace = (value: string) => /^[\r\n\s\t\f\v]+$/.test(value) const INNER_START_OFFSET = '