From 9ca07e2e4bf00a4d245a1effd0096243c487b00d Mon Sep 17 00:00:00 2001 From: e11sy Date: Sat, 4 May 2024 19:47:47 +0300 Subject: [PATCH 1/4] added naming-convention for `property` selector - added naming convention for property selector to allow 2xx, 2[0-9][0-9] and application/json as property names - added test for this case --- src/configs/typescript.mjs | 19 ++++++++++++++++++- test/rules/typescript/naming-convention.ts | 6 ++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 test/rules/typescript/naming-convention.ts diff --git a/src/configs/typescript.mjs b/src/configs/typescript.mjs index ec9d343..5e6b8fb 100644 --- a/src/configs/typescript.mjs +++ b/src/configs/typescript.mjs @@ -150,7 +150,24 @@ export default [ format: [ 'PascalCase', ], - }], + }, + { + selector: 'property', + format: ['camelCase'], + filter: { + regex: '^(?!(2xx|2[0-9][0-9]|application/json)$).*', + match: true, + }, + }, + { + selector: 'property', + format: null, + filter: { + regex: '^(2xx|2[0-9][0-9]|application/json)$', + match: true, + }, + }, + ], 'no-shadow': 'off', '@typescript-eslint/no-shadow': 'error', '@typescript-eslint/consistent-type-imports': 'error', diff --git a/test/rules/typescript/naming-convention.ts b/test/rules/typescript/naming-convention.ts new file mode 100644 index 0000000..494069f --- /dev/null +++ b/test/rules/typescript/naming-convention.ts @@ -0,0 +1,6 @@ +const response = { + '2xx': 'value', + 205: 'value', + 305: 'value', + 'application/json': 'value', +}; From e1f8d733f9507b5e424317b2cc428ba915828b7f Mon Sep 17 00:00:00 2001 From: e11sy Date: Sat, 4 May 2024 19:57:33 +0300 Subject: [PATCH 2/4] update version to 2.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 15d3983..58fdc93 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-codex", - "version": "2.0.0", + "version": "2.0.1", "main": "index.js", "repository": "github:codex-team/eslint-config", "license": "MIT", From 6e8169cb8ca8911623b5cf7953a5af9d0644e971 Mon Sep 17 00:00:00 2001 From: e11sy Date: Sat, 4 May 2024 20:08:08 +0300 Subject: [PATCH 3/4] added jsdoc --- src/configs/typescript.mjs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/configs/typescript.mjs b/src/configs/typescript.mjs index 5e6b8fb..23d03da 100644 --- a/src/configs/typescript.mjs +++ b/src/configs/typescript.mjs @@ -151,6 +151,9 @@ export default [ 'PascalCase', ], }, + /** + * Use camelCase for property names that dont satisfy regex + */ { selector: 'property', format: ['camelCase'], @@ -159,6 +162,9 @@ export default [ match: true, }, }, + /** + * Property names that satisfy regex are used without any format rules + */ { selector: 'property', format: null, From ee1fdf79f13bfa66a72eb4965b70eb66a1410cbe Mon Sep 17 00:00:00 2001 From: e11sy <130844513+e11sy@users.noreply.github.com> Date: Sat, 4 May 2024 20:12:13 +0300 Subject: [PATCH 4/4] Update src/configs/typescript.mjs Co-authored-by: Peter Savchenko --- src/configs/typescript.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/configs/typescript.mjs b/src/configs/typescript.mjs index 23d03da..e51efe5 100644 --- a/src/configs/typescript.mjs +++ b/src/configs/typescript.mjs @@ -163,7 +163,7 @@ export default [ }, }, /** - * Property names that satisfy regex are used without any format rules + * Allows "2xx" (and similar) as a property name, used in the API response schema */ { selector: 'property',