-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6cc74a3
commit f22c2f7
Showing
19 changed files
with
588 additions
and
808 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { ESLintUtils } from '@typescript-eslint/utils' | ||
|
||
export type ExtraRuleDocs = { | ||
recommended: 'strict' | 'error' | 'warn' | ||
} | ||
|
||
export const createRule = ESLintUtils.RuleCreator<ExtraRuleDocs>( | ||
(name) => `https://github.com/lingui/eslint-plugin?tab=readme-ov-file#${name}`, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,63 @@ | ||
import noExpressionInMessageRule from './rules/no-expression-in-message' | ||
import noUnlocalizedStringsRule from './rules/no-unlocalized-strings' | ||
import noSingleTagToTranslateRule from './rules/no-single-tag-to-translate' | ||
import noSingleVariablesToTranslateRule from './rules/no-single-variables-to-translate' | ||
import tCallInFunctionRule from './rules/t-call-in-function' | ||
import textRestrictionsRule from './rules/text-restrictions' | ||
import noTransInsideTransRule from './rules/no-trans-inside-trans' | ||
import * as noExpressionInMessageRule from './rules/no-expression-in-message' | ||
import * as noUnlocalizedStringsRule from './rules/no-unlocalized-strings' | ||
import * as noSingleTagToTranslateRule from './rules/no-single-tag-to-translate' | ||
import * as noSingleVariablesToTranslateRule from './rules/no-single-variables-to-translate' | ||
import * as tCallInFunctionRule from './rules/t-call-in-function' | ||
import * as textRestrictionsRule from './rules/text-restrictions' | ||
import * as noTransInsideTransRule from './rules/no-trans-inside-trans' | ||
|
||
import { ESLint, Linter } from 'eslint' | ||
import { FlatConfig, RuleModule } from '@typescript-eslint/utils/ts-eslint' | ||
|
||
export const rules = { | ||
'no-expression-in-message': noExpressionInMessageRule, | ||
'no-unlocalized-strings': noUnlocalizedStringsRule, | ||
'no-single-tag-to-translate': noSingleTagToTranslateRule, | ||
'no-single-variables-to-translate': noSingleVariablesToTranslateRule, | ||
't-call-in-function': tCallInFunctionRule, | ||
'text-restrictions': textRestrictionsRule, | ||
'no-trans-inside-trans': noTransInsideTransRule, | ||
[noExpressionInMessageRule.name]: noExpressionInMessageRule.rule, | ||
[noUnlocalizedStringsRule.name]: noUnlocalizedStringsRule.rule, | ||
[noSingleTagToTranslateRule.name]: noSingleTagToTranslateRule.rule, | ||
[noSingleVariablesToTranslateRule.name]: noSingleVariablesToTranslateRule.rule, | ||
[tCallInFunctionRule.name]: tCallInFunctionRule.rule, | ||
[textRestrictionsRule.name]: textRestrictionsRule.rule, | ||
[noTransInsideTransRule.name]: noTransInsideTransRule.rule, | ||
} | ||
|
||
type RuleKey = keyof typeof rules | ||
|
||
interface Plugin extends Omit<ESLint.Plugin, 'rules'> { | ||
rules: Record<RuleKey, RuleModule<any, any, any>> | ||
configs: { | ||
recommended: ESLint.ConfigData | ||
'flat/recommended': Array<Linter.FlatConfig> | ||
} | ||
} | ||
|
||
const plugin: Plugin = { | ||
meta: { | ||
name: 'eslint-plugin-lingui', | ||
}, | ||
configs: {} as Plugin['configs'], | ||
rules, | ||
} | ||
|
||
const recommendedRules: { [K in RuleKey as `lingui/${K}`]?: FlatConfig.RuleLevel } = { | ||
'lingui/t-call-in-function': 'error', | ||
'lingui/no-single-tag-to-translate': 'warn', | ||
'lingui/no-single-variable-to-translate': 'warn', | ||
'lingui/no-trans-inside-trans': 'warn', | ||
} | ||
|
||
// Assign configs here so we can reference `plugin` | ||
Object.assign(plugin.configs, { | ||
recommended: { | ||
plugins: ['lingui'], | ||
rules: recommendedRules, | ||
}, | ||
'flat/recommended': [ | ||
{ | ||
plugins: { | ||
lingui: plugin, | ||
}, | ||
rules: recommendedRules, | ||
}, | ||
], | ||
}) | ||
|
||
export default plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.