Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Supporter la Flat config ESLint #22

Merged
merged 7 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
const { resolve } = require('node:path');

const js = require('@eslint/js');
const { fixupPluginRules } = require('@eslint/compat');
const comments = require('@eslint-community/eslint-plugin-eslint-comments/configs');
const eslintPluginYml = require('eslint-plugin-yml');
const simpleImportSort = require('eslint-plugin-simple-import-sort');
const i18nJson = require('eslint-plugin-i18n-json');
const pixPlugin = require('./index.js');

module.exports = [
yannbertrand marked this conversation as resolved.
Show resolved Hide resolved
js.configs.recommended,
...eslintPluginYml.configs['flat/standard'],
comments.recommended,
{
plugins: {
'i18n-json': fixupPluginRules(i18nJson),
'@1024pix': pixPlugin,
'simple-import-sort': simpleImportSort,
},
rules: {
'arrow-parens': ['error', 'always'],
'comma-dangle': ['error', 'always-multiline'],
'computed-property-spacing': ['error', 'never'],
'eol-last': ['error'],
'@eslint-community/eslint-comments/no-unused-disable': ['error'],
indent: [
'error',
2,
{
SwitchCase: 1,
},
],
'keyword-spacing': ['error'],
'linebreak-style': ['error', 'unix'],
'no-multiple-empty-lines': [
'error',
{
max: 1,
maxEOF: 1,
},
],
'no-restricted-syntax': [
'error',
{
selector:
'NewExpression[callee.name=Date][arguments.length=1][arguments.0.type=Literal]:not([arguments.0.value=/^[12][0-9]{3}-(0[0-9]|1[0-2])-([0-2][0-9]|3[01])(T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]Z)?$/])',
message: "Use only ISO8601 UTC syntax ('2019-03-12T01:02:03Z') in Date constructor",
},
{
selector:
"CallExpression[callee.object.object.name='faker'][callee.object.property.name='internet'][callee.property.name='email']",
message: 'Use only faker.internet.exampleEmail()',
},
],
'no-restricted-globals': [
'error',
{
name: 'fetch',
message: "Use import fetch from 'fetch'",
},
],
'no-unused-vars': [
'error',
{
argsIgnorePattern: '_',
},
],
'no-var': ['error'],
'object-curly-spacing': ['error', 'always'],
'prefer-const': ['error'],
quotes: ['error', 'single'],
semi: ['error', 'always'],
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
'space-before-blocks': ['error'],
'space-before-function-paren': [
'error',
{
anonymous: 'never',
named: 'never',
asyncArrow: 'ignore',
},
],
'space-in-parens': ['error'],
'space-infix-ops': ['error'],
'func-call-spacing': ['error'],
'key-spacing': ['error'],
'comma-spacing': ['error'],
'no-trailing-spaces': ['error'],
'no-multi-spaces': ['error'],
'yml/quotes': [
'error',
{
prefer: 'single',
avoidEscape: true,
},
],
'i18n-json/sorted-keys': [
'error',
{
sortFunctionPath: resolve(__dirname, './json/sort-translations.js'),
},
],
'@1024pix/no-sinon-stub-with-args-oneliner': 'error',
},
},
];
16 changes: 16 additions & 0 deletions json/sort-translations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = (translations) => {
return Object.keys(translations).sort((keyA, keyB) => {
if (keyB == 'current-lang' || keyB == 'title') {
return 1;
} else if (keyA == 'current-lang' || keyA == 'title') {
return -1;
}
if (keyA == keyB) {
return 0;
} else if (keyA < keyB) {
return -1;
} else {
return 1;
}
});
};
73 changes: 73 additions & 0 deletions json/sort-translations.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const { describe, it } = require('node:test');
const { deepStrictEqual } = require('node:assert');
const sortTranslations = require('./sort-translations.js');

describe('#sortTranslation', () => {
it('should sort keys alphabetically', () => {
// Given
const translations = {
d: 'Daniel',
a: 'Alpha',
c: 'Charly',
b: 'Beta',
};
const expectedResult = ['a', 'b', 'c', 'd'];

// When
const result = sortTranslations(translations);

// Then
deepStrictEqual(result, expectedResult);
});

it('should put the `title` key on top', () => {
// Given
const translations = {
d: 'Daniel',
a: 'Alpha',
title: 'should be first',
c: 'Charly',
b: 'Beta',
};
const expectedResult = ['title', 'a', 'b', 'c', 'd'];

// When
const result = sortTranslations(translations);

// Then
deepStrictEqual(result, expectedResult);
});

it('should put the `current-lang` key on top', () => {
// Given
const translations = {
d: 'Daniel',
a: 'Alpha',
'current-lang': 'should be first',
c: 'Charly',
b: 'Beta',
};
const expectedResult = ['current-lang', 'a', 'b', 'c', 'd'];

// When
const result = sortTranslations(translations);

// Then
deepStrictEqual(result, expectedResult);
});

it('should put the `title` key before the `current-lang` key', () => {
// Given
const translations = {
title: 'should be second',
'current-lang': 'should be first',
};
const expectedResult = ['title', 'current-lang'];

// When
const result = sortTranslations(translations);

// Then
deepStrictEqual(result, expectedResult);
});
});
Loading