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

fix(eslint-plugin): [naming-convention] allow an array of selectors with types and modifiers #2415

Merged
merged 5 commits into from Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 16 additions & 16 deletions packages/eslint-plugin/src/rules/naming-convention.ts
Expand Up @@ -278,24 +278,24 @@ function selectorsSchema(): JSONSchema.JSONSchema4 {
},
additionalItems: false,
},
modifiers: {
type: 'array',
items: {
type: 'string',
enum: util.getEnumNames(Modifiers),
},
additionalItems: false,
},
types: {
type: 'array',
items: {
type: 'string',
enum: util.getEnumNames(TypeModifiers),
},
additionalItems: false,
},
},
},
modifiers: {
type: 'array',
items: {
type: 'string',
enum: util.getEnumNames(Modifiers),
},
additionalItems: false,
},
types: {
type: 'array',
items: {
type: 'string',
enum: util.getEnumNames(TypeModifiers),
},
additionalItems: false,
},
required: ['selector', 'format'],
additionalProperties: false,
};
Expand Down
105 changes: 105 additions & 0 deletions packages/eslint-plugin/tests/rules/naming-convention.test.ts
Expand Up @@ -835,6 +835,77 @@ ruleTester.run('naming-convention', rule, {
},
],
},
{
code: `
let isFoo = 1;
class foo {
shouldBoo: number;
}
`,
parserOptions,
options: [
{
selector: ['variable', 'parameter', 'property', 'accessor'],
types: ['number'],
format: ['PascalCase'],
prefix: ['is', 'should', 'has', 'can', 'did', 'will'],
},
],
},
{
code: `
class foo {
private readonly FooBoo: boolean;
}
`,
parserOptions,
options: [
{
selector: ['property', 'accessor'],
types: ['boolean'],
modifiers: ['private', 'readonly'],
format: ['PascalCase'],
},
],
},
{
code: `
class foo {
private fooBoo: number;
}
`,
options: [
{
selector: ['property', 'accessor'],
modifiers: ['private'],
format: ['camelCase'],
},
],
},
{
code: `
const isfooBar = 1;
function fun(goodfunFoo: number) {}
class foo {
private VanFooBar: number;
}
`,
parserOptions,
options: [
{
selector: ['property', 'accessor'],
modifiers: ['private'],
format: ['StrictPascalCase'],
prefix: ['Van'],
},
{
selector: ['variable', 'parameter'],
types: ['number'],
format: ['camelCase'],
prefix: ['is', 'good'],
},
],
},
],
invalid: [
{
Expand Down Expand Up @@ -1166,5 +1237,39 @@ ruleTester.run('naming-convention', rule, {
},
],
},
{
code: `
const myfoo_bar = 'abcs';
function fun(myfoo: string) {}
class foo {
Myfoo: string;
}
`,
options: [
{
selector: ['variable', 'property', 'parameter'],
types: ['string'],
format: ['PascalCase'],
prefix: ['my', 'My'],
},
],
parserOptions,
errors: Array(3).fill({ messageId: 'doesNotMatchFormatTrimmed' }),
},
{
code: `
class foo {
private readonly fooBar: boolean;
}
`,
options: [
{
selector: ['property', 'accessor'],
modifiers: ['private', 'readonly'],
format: ['PascalCase'],
},
],
errors: [{ messageId: 'doesNotMatchFormat' }],
},
],
});