🚨(i18n) add linter to i18n package
We need to add a linter to the i18n package, we are mainly interested by the jest linting rules so we create a jest eslint config pluggable our other configs and to the i18n eslint config.
This commit is contained in:
20
src/frontend/packages/eslint-config-people/.eslintrc.js
Normal file
20
src/frontend/packages/eslint-config-people/.eslintrc.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const common = require('./common');
|
||||
|
||||
module.exports = {
|
||||
root: true,
|
||||
settings: {
|
||||
react: {
|
||||
version: 'detect',
|
||||
},
|
||||
},
|
||||
extends: [
|
||||
'plugin:prettier/recommended',
|
||||
'plugin:import/recommended',
|
||||
'plugin:react/recommended',
|
||||
],
|
||||
rules: common.globalRules,
|
||||
parserOptions: {
|
||||
sourceType: 'module',
|
||||
ecmaVersion: 'latest',
|
||||
},
|
||||
};
|
||||
@@ -1,58 +1,66 @@
|
||||
const eslintTS = {
|
||||
files: ["*.ts", "*.tsx"],
|
||||
extends: [
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:@typescript-eslint/recommended-requiring-type-checking",
|
||||
],
|
||||
parser: "@typescript-eslint/parser", // Specifies the ESLint parser
|
||||
parserOptions: {
|
||||
tsconfigRootDir: __dirname,
|
||||
project: ["./tsconfig.json"],
|
||||
},
|
||||
rules: {
|
||||
"@typescript-eslint/no-explicit-any": "error",
|
||||
"@typescript-eslint/no-non-null-assertion": "error",
|
||||
"sort-imports": [
|
||||
"error",
|
||||
{
|
||||
ignoreDeclarationSort: true,
|
||||
},
|
||||
const eslintTS = [
|
||||
{
|
||||
files: ['*.ts', '*.tsx'],
|
||||
extends: [
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:@typescript-eslint/recommended-requiring-type-checking',
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const globalRules = {
|
||||
"block-scoped-var": "error",
|
||||
curly: ["error", "all"],
|
||||
"import/no-duplicates": ["error", { considerQueryString: false }],
|
||||
"import/order": [
|
||||
"error",
|
||||
{
|
||||
alphabetize: {
|
||||
order: "asc",
|
||||
},
|
||||
groups: ["builtin", "external", "internal", "parent", "sibling", "index"],
|
||||
pathGroups: [
|
||||
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
|
||||
parserOptions: {
|
||||
tsconfigRootDir: __dirname,
|
||||
project: ['./tsconfig.json'],
|
||||
},
|
||||
rules: {
|
||||
'@typescript-eslint/no-explicit-any': 'error',
|
||||
'@typescript-eslint/no-non-null-assertion': 'error',
|
||||
'sort-imports': [
|
||||
'error',
|
||||
{
|
||||
pattern: "@/**",
|
||||
group: "internal",
|
||||
ignoreDeclarationSort: true,
|
||||
},
|
||||
],
|
||||
pathGroupsExcludedImportTypes: ["builtin"],
|
||||
"newlines-between": "always",
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['*.d.ts'],
|
||||
rules: {
|
||||
'no-unused-vars': 'off',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const globalRules = {
|
||||
'block-scoped-var': 'error',
|
||||
curly: ['error', 'all'],
|
||||
'import/no-duplicates': ['error', { considerQueryString: false }],
|
||||
'import/order': [
|
||||
'error',
|
||||
{
|
||||
alphabetize: {
|
||||
order: 'asc',
|
||||
},
|
||||
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
|
||||
pathGroups: [
|
||||
{
|
||||
pattern: '@/**',
|
||||
group: 'internal',
|
||||
},
|
||||
],
|
||||
pathGroupsExcludedImportTypes: ['builtin'],
|
||||
'newlines-between': 'always',
|
||||
},
|
||||
],
|
||||
"no-alert": "error",
|
||||
"no-unused-vars": [
|
||||
"error",
|
||||
{ varsIgnorePattern: "^_", argsIgnorePattern: "^_" },
|
||||
'no-alert': 'error',
|
||||
'no-unused-vars': [
|
||||
'error',
|
||||
{ varsIgnorePattern: '^_', argsIgnorePattern: '^_' },
|
||||
],
|
||||
"react/jsx-curly-brace-presence": [
|
||||
"error",
|
||||
{ props: "never", children: "never", propElementValues: "always" },
|
||||
'react/jsx-curly-brace-presence': [
|
||||
'error',
|
||||
{ props: 'never', children: 'never', propElementValues: 'always' },
|
||||
],
|
||||
"sort-imports": [
|
||||
"error",
|
||||
'sort-imports': [
|
||||
'error',
|
||||
{
|
||||
ignoreDeclarationSort: true,
|
||||
},
|
||||
|
||||
49
src/frontend/packages/eslint-config-people/jest.js
Normal file
49
src/frontend/packages/eslint-config-people/jest.js
Normal file
@@ -0,0 +1,49 @@
|
||||
const common = require('./common');
|
||||
|
||||
module.exports = {
|
||||
extends: ['plugin:prettier/recommended', 'plugin:react/recommended'],
|
||||
rules: common.globalRules,
|
||||
settings: {
|
||||
react: {
|
||||
version: 'detect',
|
||||
},
|
||||
},
|
||||
overrides: [
|
||||
...common.eslintTS,
|
||||
{
|
||||
files: ['*.spec.*', '*.test.*', '**/__mock__/**/*'],
|
||||
plugins: ['jest'],
|
||||
extends: ['plugin:jest/recommended', 'plugin:testing-library/react'],
|
||||
rules: {
|
||||
'@typescript-eslint/ban-types': 'off',
|
||||
'@typescript-eslint/no-empty-function': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||
'@typescript-eslint/no-unsafe-argument': 'off',
|
||||
'@typescript-eslint/no-unsafe-assignment': 'off',
|
||||
'@typescript-eslint/no-unsafe-call': 'off',
|
||||
'@typescript-eslint/no-unsafe-member-access': 'off',
|
||||
'@typescript-eslint/no-unsafe-return': 'off',
|
||||
'testing-library/no-await-sync-events': [
|
||||
'error',
|
||||
{ eventModules: ['fire-event'] },
|
||||
],
|
||||
'testing-library/await-async-events': [
|
||||
'error',
|
||||
{
|
||||
eventModule: 'userEvent',
|
||||
},
|
||||
],
|
||||
'testing-library/no-manual-cleanup': 'off',
|
||||
'@typescript-eslint/no-unused-vars': [
|
||||
'error',
|
||||
{ varsIgnorePattern: '^_', argsIgnorePattern: '^_' },
|
||||
],
|
||||
'react/display-name': 0,
|
||||
'jest/expect-expect': 'error',
|
||||
'@typescript-eslint/unbound-method': 'off',
|
||||
'jest/unbound-method': 'error',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -1,65 +1,29 @@
|
||||
const common = require("./common");
|
||||
const common = require('./common');
|
||||
|
||||
module.exports = {
|
||||
extends: [
|
||||
"next",
|
||||
"plugin:prettier/recommended",
|
||||
"plugin:@tanstack/eslint-plugin-query/recommended",
|
||||
"plugin:jsx-a11y/recommended",
|
||||
'people/jest',
|
||||
'next',
|
||||
'plugin:prettier/recommended',
|
||||
'plugin:@tanstack/eslint-plugin-query/recommended',
|
||||
'plugin:jsx-a11y/recommended',
|
||||
],
|
||||
settings: {
|
||||
"jsx-a11y": {
|
||||
polymorphicPropName: "as",
|
||||
'jsx-a11y': {
|
||||
polymorphicPropName: 'as',
|
||||
components: {
|
||||
Input: "input",
|
||||
Button: "button",
|
||||
Box: "div",
|
||||
Text: "span",
|
||||
Select: "select",
|
||||
Input: 'input',
|
||||
Button: 'button',
|
||||
Box: 'div',
|
||||
Text: 'span',
|
||||
Select: 'select',
|
||||
},
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
...common.globalRules,
|
||||
"react-hooks/rules-of-hooks": "error",
|
||||
"react-hooks/exhaustive-deps": "error",
|
||||
'react-hooks/rules-of-hooks': 'error',
|
||||
'react-hooks/exhaustive-deps': 'error',
|
||||
},
|
||||
overrides: [
|
||||
common.eslintTS,
|
||||
{
|
||||
files: ["*.spec.*", "*.test.*", "**/__mock__/**/*"],
|
||||
plugins: ["jest"],
|
||||
extends: ["plugin:jest/recommended", "plugin:testing-library/react"],
|
||||
rules: {
|
||||
"@typescript-eslint/ban-types": "off",
|
||||
"@typescript-eslint/no-empty-function": "off",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"@typescript-eslint/no-non-null-assertion": "off",
|
||||
"@typescript-eslint/no-unsafe-argument": "off",
|
||||
"@typescript-eslint/no-unsafe-assignment": "off",
|
||||
"@typescript-eslint/no-unsafe-call": "off",
|
||||
"@typescript-eslint/no-unsafe-member-access": "off",
|
||||
"@typescript-eslint/no-unsafe-return": "off",
|
||||
"testing-library/no-await-sync-events": [
|
||||
"error",
|
||||
{ eventModules: ["fire-event"] },
|
||||
],
|
||||
"testing-library/await-async-events": [
|
||||
"error",
|
||||
{
|
||||
eventModule: "userEvent",
|
||||
},
|
||||
],
|
||||
"testing-library/no-manual-cleanup": "off",
|
||||
"@typescript-eslint/no-unused-vars": [
|
||||
"error",
|
||||
{ varsIgnorePattern: "^_", argsIgnorePattern: "^_" },
|
||||
],
|
||||
"react/display-name": 0,
|
||||
"jest/expect-expect": "error",
|
||||
"@typescript-eslint/unbound-method": "off",
|
||||
"jest/unbound-method": "error",
|
||||
},
|
||||
},
|
||||
],
|
||||
overrides: common.eslintTS,
|
||||
};
|
||||
|
||||
@@ -2,17 +2,22 @@
|
||||
"name": "eslint-config-people",
|
||||
"version": "0.1.0",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"lint": "eslint --ext .js ."
|
||||
},
|
||||
"dependencies": {
|
||||
"@next/eslint-plugin-next": "14.0.4",
|
||||
"@tanstack/eslint-plugin-query": "5.18.1",
|
||||
"@typescript-eslint/eslint-plugin": "6.20.0",
|
||||
"eslint": "8.56.0",
|
||||
"eslint-config-next": "14.1.0",
|
||||
"eslint-config-prettier": "9.1.0",
|
||||
"eslint-plugin-import": "2.29.1",
|
||||
"eslint-plugin-jest": "27.6.3",
|
||||
"eslint-plugin-jsx-a11y": "6.8.0",
|
||||
"eslint-plugin-playwright": "0.22.2",
|
||||
"eslint-plugin-prettier": "5.1.3",
|
||||
"eslint-plugin-testing-library": "6.2.0",
|
||||
"@next/eslint-plugin-next": "14.1.0",
|
||||
"eslint-plugin-playwright": "0.22.2"
|
||||
"eslint-plugin-react": "7.33.2",
|
||||
"eslint-plugin-testing-library": "6.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
const common = require("./common");
|
||||
const common = require('./common');
|
||||
|
||||
module.exports = {
|
||||
extends: ["next", "plugin:prettier/recommended"],
|
||||
parserOptions: {
|
||||
babelOptions: {
|
||||
presets: [require.resolve("next/babel")],
|
||||
extends: ['next', 'plugin:prettier/recommended'],
|
||||
settings: {
|
||||
react: {
|
||||
version: 'detect',
|
||||
},
|
||||
},
|
||||
rules: common.globalRules,
|
||||
parserOptions: {
|
||||
babelOptions: {
|
||||
presets: [require.resolve('next/babel')],
|
||||
},
|
||||
},
|
||||
rules: { ...common.globalRules, '@next/next/no-html-link-for-pages': 'off' },
|
||||
overrides: [
|
||||
common.eslintTS,
|
||||
...common.eslintTS,
|
||||
{
|
||||
files: ["*.spec.*", "*.test.*", "**/__mock__/**/*"],
|
||||
extends: ["plugin:playwright/recommended"],
|
||||
plugins: ["playwright"],
|
||||
files: ['*.spec.*', '*.test.*', '**/__mock__/**/*'],
|
||||
extends: ['plugin:playwright/recommended'],
|
||||
plugins: ['playwright'],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
10
src/frontend/packages/i18n/.eslintrc.js
Normal file
10
src/frontend/packages/i18n/.eslintrc.js
Normal file
@@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
extends: ['people/jest', 'plugin:import/recommended'],
|
||||
parserOptions: {
|
||||
sourceType: 'module',
|
||||
ecmaVersion: 'latest',
|
||||
tsconfigRootDir: __dirname,
|
||||
project: ['./tsconfig.json'],
|
||||
},
|
||||
};
|
||||
@@ -1,15 +1,15 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import { hideBin } from "yargs/helpers";
|
||||
import yargs from "yargs/yargs";
|
||||
import { hideBin } from 'yargs/helpers';
|
||||
import yargs from 'yargs/yargs';
|
||||
|
||||
// Get our args
|
||||
const argv = yargs(hideBin(process.argv)).argv;
|
||||
const { app, output } = argv;
|
||||
|
||||
const folderPath = "./locales/" + app;
|
||||
const namefile = "translations.json";
|
||||
const folderPath = './locales/' + app;
|
||||
const namefile = 'translations.json';
|
||||
const jsonI18n = {};
|
||||
|
||||
// Fetch the files in the locales folder
|
||||
@@ -31,7 +31,7 @@ fs.readdirSync(folderPath).map((language) => {
|
||||
throw new Error(`File ${pathTranslateFile} not found!`);
|
||||
}
|
||||
|
||||
const json = JSON.parse(fs.readFileSync(pathTranslateFile, "utf8"));
|
||||
const json = JSON.parse(fs.readFileSync(pathTranslateFile, 'utf8'));
|
||||
|
||||
// Transform the json file to the format expected by i18next
|
||||
const jsonKeyMessage = {};
|
||||
@@ -48,6 +48,6 @@ if (!Object.keys(jsonI18n).length) {
|
||||
}
|
||||
|
||||
// Write the file to the output
|
||||
fs.writeFileSync(output, JSON.stringify(jsonI18n), "utf8");
|
||||
fs.writeFileSync(output, JSON.stringify(jsonI18n), 'utf8');
|
||||
|
||||
console.log(`${app} translations deployed!`);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const config = {
|
||||
customValueTemplate: {
|
||||
message: "${key}",
|
||||
description: "${description}",
|
||||
message: '${key}',
|
||||
description: '${description}',
|
||||
},
|
||||
keepRemoved: true,
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export default {
|
||||
rootDir: "./",
|
||||
testEnvironment: "node",
|
||||
rootDir: './',
|
||||
testEnvironment: 'node',
|
||||
transform: {
|
||||
"^.+\\.(ts)$": "ts-jest",
|
||||
'^.+\\.(ts)$': 'ts-jest',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -7,11 +7,14 @@
|
||||
"extract-translation:desk": "yarn i18next ../../apps/desk/**/*.{ts,tsx} -c ./i18next-parser.config.mjs -o ./locales/desk/translations-crowdin.json",
|
||||
"format-deploy": "yarn format-deploy:desk",
|
||||
"format-deploy:desk": "node ./format-deploy.mjs --app=desk --output=../../apps/desk/src/i18n/translations.json",
|
||||
"lint": "eslint --ext .js,.ts,.mjs .",
|
||||
"test": "jest"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/jest": "29.5.11",
|
||||
"@types/node": "20.11.6",
|
||||
"eslint-config-people": "*",
|
||||
"eslint-plugin-import": "2.29.1",
|
||||
"i18next-parser": "8.8.0",
|
||||
"jest": "29.7.0",
|
||||
"ts-jest": "29.1.2",
|
||||
|
||||
Reference in New Issue
Block a user