-
Hey, "@typescript-eslint/naming-convention": [
"error",
{ "selector": "default", "format": null },
{
"selector": "typeAlias",
"format": ["PascalCase"],
"prefix": ["T"]
}
],
"id-length": [
"error",
{ "min": 2, "exceptions": ["y", "z", "_"] }
] So basically:
Here's what I got so far in "useNamingConvention": {
"level": "error",
"options": {
"strictCase": false,
"conventions": [
{
"selector": {
"kind": "typeAlias"
},
"match": "T.{2,}",
"formats": ["PascalCase"]
},
{
"selector": {
"kind": "typeParameter"
},
"match": ".*",
"formats": ["PascalCase"]
},
{
"selector": {
"kind": "variable"
},
"match": ".{2,}",
"formats": ["camelCase"]
},
{
"selector": {
"kind": "any"
},
"match": ".{2,}",
"formats": ["camelCase", "CONSTANT_CASE", "PascalCase", "snake_case"]
}
]
} And here are my test files:
import React from 'react';
function track(data: { event: string; interaction_name: string }) {
console.log(data);
}
// ------------------------------
// COMPARISON
// 1. Prefixed
type TFoo = {
bar: string;
baz: number;
};
// 2. Uppercased
type TUppercaseType = {
foo: string;
};
// 3. Long enough
type TLongEnough = {
foo: string;
};
// 4. Long enough
[1, 2, 3].map((num) => num + 1);
// 5. Using camelCase
const fooBar = 1;
let barBaz = 2;
barBaz = 3;
// ------------------------------
// FALSE POSITIVES CHECK
// 6. Any format allowed
track({
event: 'foo',
interaction_name: 'bar',
});
// 7. __html allowed
// biome-ignore lint/security/noDangerouslySetInnerHtml: Not what this test is about
<div dangerouslySetInnerHTML={{ __html: '<p>foo</p>' }} />;
// 8. <T> allowed
function doubleArray<T>(arr: T[]): T[] {
return arr.concat(arr);
}
// 9. zod allowed
import z from 'zod';
// ------------------------------
// IGNORE
export default 69;
// 1. Not prefixed
type Foo = {
bar: string;
baz: number;
};
// 2. Lowercased
type lowercaseType = {
foo: string;
};
// 3. Too short
type T = {
foo: string;
};
// 4. Too short
[1, 2, 3].map((n) => n + 1);
// 5. Not using camelCase
const foo_bar = 1;
let bar_baz = 2;
bar_baz = 3; My config finds first 4 issues just fine, but:
I have a suspicion that there is a way to make this infinitely easier, but I got completely lost. I can't seem to find a way to just tell Biome to check what my original intention is: types starting with T, no one-character variables, don't do ANYTHING else. I feel like the last selector does more harm than good, but without it, the situation is even worse. How do I proceed? TIA! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
If you use I could test the following config: "useNamingConvention": {
"level": "error",
"options": {
"strictCase": false,
"conventions": [
{
"selector": {
"kind": "typeAlias"
},
"match": "T(.{2,})",
"formats": ["PascalCase"]
},
{
"selector": {
"kind": "typeParameter"
},
"formats": ["PascalCase"]
},
{
"selector": {
"kind": "objectLiteralMember"
},
// accept everything
"match": ".*"
},
{
"selector": {
"kind": "any"
},
"match": "[yz_]|(.{2,})"
// Here I didn't specify `formats` in order to apply the following conventions, including the default ones.
},
{
"selector": {
"kind": "variable"
},
"formats": ["camelCase"]
}
]
} Let me know if you don't understand something. |
Beta Was this translation helpful? Give feedback.
If you use
match
andformats
, you have to capture a string in order to check againstformats
; otherwiseformats
is never used.Also, if you don't specify
formats
and capture a string withmatch
, the captured string is automatically forwarded to the next selection.I could test the following config: