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

feat(eslint-plugin): [naming-convention] support the auto-accessor syntax #8084

Merged
merged 30 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1662bd3
fix: support auto-accessor for naming convention
arka1002 Dec 17, 2023
25feaba
chore: fix CI failures
arka1002 Dec 17, 2023
2d47b74
Merge branch 'main' into issue-7823
arka1002 Dec 19, 2023
c1b1796
Merge branch 'main' into issue-7823
arka1002 Dec 23, 2023
1fe2d01
Merge branch 'main' into issue-7823
arka1002 Jan 4, 2024
2bb04b7
Merge branch 'main' into issue-7823
arka1002 Jan 4, 2024
4636e6d
Merge branch 'main' into issue-7823
arka1002 Jan 5, 2024
0149a62
chore: making auto-accessor a modifier of accessor
arka1002 Jan 5, 2024
2351b09
chore: fix prettier issues
arka1002 Jan 6, 2024
45a5118
chore: docs for auto-accessor syntax
arka1002 Jan 6, 2024
320320e
Merge branch 'main' into issue-7823
arka1002 Jan 7, 2024
c08c4cf
fix: make autoAccessor a selector
arka1002 Jan 8, 2024
3762356
fix: prettier and docs
arka1002 Jan 8, 2024
c4ae266
fix: small typo
arka1002 Jan 8, 2024
ec931d8
Merge branch 'main' into issue-7823
arka1002 Jan 8, 2024
9a42efe
Merge branch 'main' into issue-7823
arka1002 Jan 11, 2024
47fd96a
chore: add more test coverage and docs
arka1002 Jan 12, 2024
3d05845
Merge branch 'main' into issue-7823
arka1002 Jan 12, 2024
bd7947a
fix: support the abstract accessor
arka1002 Jan 13, 2024
9148131
chore: change accessor to classicAccessor selector
arka1002 Jan 13, 2024
d8114e8
chore: group classic and auto selectors
arka1002 Jan 13, 2024
468549d
chore: fix a small type error
arka1002 Jan 13, 2024
9fbc50c
Merge branch 'main' into issue-7823
arka1002 Jan 13, 2024
e6a1d27
chore: add docs
arka1002 Jan 13, 2024
813b1ec
Merge branch 'main' into issue-7823
arka1002 Jan 16, 2024
11d81c1
chore: slight mistake
arka1002 Feb 5, 2024
16eb834
Merge branch 'issue-7823' of github.com:arka1002/typescript-eslint in…
arka1002 Feb 5, 2024
88acaae
chore: add accessor test file
arka1002 Feb 6, 2024
eb935d0
chore: move docs
arka1002 Feb 21, 2024
8f1c37d
fix selector
bradzacher Feb 22, 2024
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
3 changes: 3 additions & 0 deletions packages/eslint-plugin/docs/rules/naming-convention.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ Individual Selectors match specific, well-defined sets. There is no overlap betw
- `accessor` - matches any accessor.
- Allowed `modifiers`: `abstract`, `override`, `private`, `protected`, `public`, `requiresQuotes`, `static`.
- Allowed `types`: `array`, `boolean`, `function`, `number`, `string`.
- `autoAccessor` - matches any auto-accessor.
- Allowed `modifiers`: `abstract`, `override`, `private`, `protected`, `public`, `requiresQuotes`, `static`.
- Allowed `types`: `array`, `boolean`, `function`, `number`, `string`.
bradzacher marked this conversation as resolved.
Show resolved Hide resolved
- `class` - matches any class declaration.
- Allowed `modifiers`: `abstract`, `exported`, `unused`.
- Allowed `types`: none.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ enum Selectors {

// other
import = 1 << 18,

// auto accessor
autoAccessor = 1 << 19,
bradzacher marked this conversation as resolved.
Show resolved Hide resolved
}
type SelectorsString = keyof typeof Selectors;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,15 @@ const SCHEMA: JSONSchema.JSONSchema4 = {
'static',
'override',
]),
...selectorSchema('autoAccessor', true, [
'abstract',
'private',
'protected',
'public',
'requiresQuotes',
'static',
'override',
]),
...selectorSchema('enumMember', false, ['requiresQuotes']),

...selectorSchema('typeLike', false, ['abstract', 'exported', 'unused']),
Expand Down
16 changes: 14 additions & 2 deletions packages/eslint-plugin/src/rules/naming-convention.ts
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ export default createRule<Options, MessageIds>({
| TSESTree.TSAbstractMethodDefinitionNonComputedName
| TSESTree.TSAbstractPropertyDefinitionNonComputedName
| TSESTree.TSMethodSignatureNonComputedName
| TSESTree.TSPropertySignatureNonComputedName,
| TSESTree.TSPropertySignatureNonComputedName
| TSESTree.AccessorPropertyNonComputedName,
modifiers: Set<Modifiers>,
): void {
const key = node.key;
Expand All @@ -127,7 +128,8 @@ export default createRule<Options, MessageIds>({
| TSESTree.PropertyDefinition
| TSESTree.TSAbstractMethodDefinition
| TSESTree.TSAbstractPropertyDefinition
| TSESTree.TSParameterProperty,
| TSESTree.TSParameterProperty
| TSESTree.AccessorProperty,
): Set<Modifiers> {
const modifiers = new Set<Modifiers>();
if ('key' in node && node.key.type === AST_NODE_TYPES.PrivateIdentifier) {
Expand Down Expand Up @@ -538,6 +540,16 @@ export default createRule<Options, MessageIds>({
},
},

AccessorProperty: {
validator: validators.autoAccessor,
handler: (
node: TSESTree.AccessorPropertyNonComputedName,
validator,
): void => {
const modifiers = getMemberModifiers(node);
handleMember(validator, node, modifiers);
},
},
// #endregion accessor
bradzacher marked this conversation as resolved.
Show resolved Hide resolved

// #region enumMember
Expand Down
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createTestCases } from './createTestCases';

createTestCases([
{
code: [
'class Ignored { accessor % = 10; }',
'class Ignored { accessor #% = 10; }',
'class Ignored { static accessor % = 10; }',
'class Ignored { static accessor #% = 10; }',
],
options: {
selector: 'autoAccessor',
},
},
]);

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.