Files
afilmory/plugins/eslint/eslint-recursive-sort.js
Innei c775f82153 feat(i18n): integrate i18next for internationalization support
- Added i18next and react-i18next for multi-language support in the application.
- Created localization files for English, Japanese, Korean, Traditional Chinese, and Simplified Chinese.
- Implemented translation hooks in various components to replace hardcoded strings with translatable keys.
- Updated ESLint configuration to include new i18n JSON validation rules.
- Introduced a new event bus for handling i18n updates during development.

Signed-off-by: Innei <tukon479@gmail.com>
2025-06-12 17:56:11 +08:00

50 lines
1.3 KiB
JavaScript

import { cleanJsonText, sortObjectKeys } from './utils.js'
/**
* @type {import("eslint").ESLint.Plugin}
*/
export default {
rules: {
'recursive-sort': {
meta: {
type: 'layout',
fixable: 'code',
},
create(context) {
return {
Program(node) {
if (context.filename.endsWith('.json')) {
const { sourceCode } = context
const text = cleanJsonText(sourceCode.getText())
try {
const json = JSON.parse(text)
const sortedJson = sortObjectKeys(json)
const sortedText = `${JSON.stringify(sortedJson, null, 2)}\n`
const noWhiteSpaceDiff = (a, b) =>
a.replaceAll(/\s/g, '') === b.replaceAll(/\s/g, '')
if (!noWhiteSpaceDiff(text, sortedText)) {
context.report({
node,
message: 'JSON keys are not sorted recursively',
fix(fixer) {
return fixer.replaceText(node, sortedText)
},
})
}
} catch (error) {
context.report({
node,
message: `Invalid JSON: ${error.message}`,
})
}
}
},
}
},
},
},
}