Skip to content

Commit

Permalink
style: fix comment alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Dec 21, 2024
1 parent 4dd2e1b commit b13976d
Show file tree
Hide file tree
Showing 22 changed files with 164 additions and 143 deletions.
70 changes: 35 additions & 35 deletions docs/content/rules/sort-classes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -653,46 +653,46 @@ Example:
groups: [
'static-block',
'index-signature',
+ 'input-properties', // [!code ++]
+ 'output-properties', // [!code ++]
+ 'input-properties', // [!code ++]
+ 'output-properties', // [!code ++]
'constructor',
+ 'unsorted-methods-and-other-properties', // [!code ++]
+ 'unsorted-methods-and-other-properties', // [!code ++]
['get-method', 'set-method'],
'unknown',
],
+ customGroups: [ // [!code ++]
+ { // [!code ++]
+ // `constructor()` members must not match // [!code ++]
+ // `unsorted-methods-and-other-properties` // [!code ++]
+ // so make them match this first // [!code ++]
+ groupName: 'constructor', // [!code ++]
+ selector: 'constructor', // [!code ++]
+ }, // [!code ++]
+ { // [!code ++]
+ groupName: 'input-properties', // [!code ++]
+ selector: 'property', // [!code ++]
+ modifiers: ['decorated'], // [!code ++]
+ decoratorNamePattern: 'Input', // [!code ++]
+ }, // [!code ++]
+ { // [!code ++]
+ groupName: 'output-properties', // [!code ++]
+ selector: 'property', // [!code ++]
+ modifiers: ['decorated'], // [!code ++]
+ decoratorNamePattern: 'Output', // [!code ++]
+ }, // [!code ++]
+ { // [!code ++]
+ customGroups: [ // [!code ++]
+ { // [!code ++]
+ // `constructor()` members must not match // [!code ++]
+ // `unsorted-methods-and-other-properties` // [!code ++]
+ // so make them match this first // [!code ++]
+ groupName: 'constructor', // [!code ++]
+ selector: 'constructor', // [!code ++]
+ }, // [!code ++]
+ { // [!code ++]
+ groupName: 'input-properties', // [!code ++]
+ selector: 'property', // [!code ++]
+ modifiers: ['decorated'], // [!code ++]
+ decoratorNamePattern: 'Input', // [!code ++]
+ }, // [!code ++]
+ { // [!code ++]
+ groupName: 'output-properties', // [!code ++]
+ selector: 'property', // [!code ++]
+ modifiers: ['decorated'], // [!code ++]
+ decoratorNamePattern: 'Output', // [!code ++]
+ }, // [!code ++]
+ { // [!code ++]
+ groupName: 'unsorted-methods-and-other-properties', // [!code ++]
+ type: 'unsorted', // [!code ++]
+ anyOf: [ // [!code ++]
+ { // [!code ++]
+ selector: 'method', // [!code ++]
+ }, // [!code ++]
+ { // [!code ++]
+ selector: 'property', // [!code ++]
+ }, // [!code ++]
+ ] // [!code ++]
+ }, // [!code ++]
+ ] // [!code ++]
+ type: 'unsorted', // [!code ++]
+ anyOf: [ // [!code ++]
+ { // [!code ++]
+ selector: 'method', // [!code ++]
+ }, // [!code ++]
+ { // [!code ++]
+ selector: 'property', // [!code ++]
+ }, // [!code ++]
+ ] // [!code ++]
+ }, // [!code ++]
+ ] // [!code ++]
}
```

Expand Down
8 changes: 4 additions & 4 deletions docs/content/rules/sort-decorators.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ class MyClass {
{
groups: [
'unknown',
'error' // [!code ++]
'error' // [!code ++]
],
+ customGroups: { // [!code ++]
+ error: '.*Error' // [!code ++]
+ } // [!code ++]
+ customGroups: { // [!code ++]
+ error: '.*Error' // [!code ++]
+ } // [!code ++]
}
```

Expand Down
8 changes: 4 additions & 4 deletions docs/content/rules/sort-heritage-clauses.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ interface Interface extends WithId, Logged, StartupService {
```js
{
groups: [
'withIdInterface', // [!code ++]
'withIdInterface', // [!code ++]
'unknown'
],
+ customGroups: { // [!code ++]
+ withIdInterface: '^WithId' // [!code ++]
+ } // [!code ++]
+ customGroups: { // [!code ++]
+ withIdInterface: '^WithId' // [!code ++]
+ } // [!code ++]
}
```

Expand Down
26 changes: 13 additions & 13 deletions docs/content/rules/sort-interfaces.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -541,22 +541,22 @@ interface User {
```js
{
groups: [
+ 'top', // [!code ++]
+ 'top', // [!code ++]
'unknown',
+ ['optional-multiline-member', 'bottom'] // [!code ++]
],
+ customGroups: [ // [!code ++]
+ { // [!code ++]
+ groupName: 'top', // [!code ++]
+ selector: 'property', // [!code ++]
+ elementNamePattern: '^(?:id|name)$', // [!code ++]
+ }, // [!code ++]
+ { // [!code ++]
+ groupName: 'bottom', // [!code ++]
+ selector: 'property', // [!code ++]
+ elementNamePattern: '.+_metadata$', // [!code ++]
+ } // [!code ++]
+ ] // [!code ++]
+ customGroups: [ // [!code ++]
+ { // [!code ++]
+ groupName: 'top', // [!code ++]
+ selector: 'property', // [!code ++]
+ elementNamePattern: '^(?:id|name)$', // [!code ++]
+ }, // [!code ++]
+ { // [!code ++]
+ groupName: 'bottom', // [!code ++]
+ selector: 'property', // [!code ++]
+ elementNamePattern: '.+_metadata$', // [!code ++]
+ } // [!code ++]
+ ] // [!code ++]
}
```
Expand Down
64 changes: 32 additions & 32 deletions docs/content/rules/sort-modules.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -456,39 +456,39 @@ Example:
+ 'unsorted-functions', // [!code ++]
'unknown',
],
+ customGroups: [ // [!code ++]
+ { // [!code ++]
+ groupName: 'input-types-and-interfaces', // [!code ++]
+ anyOf: [ // [!code ++]
+ { // [!code ++]
+ selector: 'type', // [!code ++]
+ elementNamePattern: 'Input'. // [!code ++]
+ }, // [!code ++]
+ { // [!code ++]
+ selector: 'interface', // [!code ++]
+ elementNamePattern: 'Input'. // [!code ++]
+ }, // [!code ++]
+ ] // [!code ++]
+ }, // [!code ++]
+ { // [!code ++]
+ customGroups: [ // [!code ++]
+ { // [!code ++]
+ groupName: 'input-types-and-interfaces', // [!code ++]
+ anyOf: [ // [!code ++]
+ { // [!code ++]
+ selector: 'type', // [!code ++]
+ elementNamePattern: 'Input'. // [!code ++]
+ }, // [!code ++]
+ { // [!code ++]
+ selector: 'interface', // [!code ++]
+ elementNamePattern: 'Input'. // [!code ++]
+ }, // [!code ++]
+ ] // [!code ++]
+ }, // [!code ++]
+ { // [!code ++]
+ groupName: 'output-types-and-interfaces', // [!code ++]
+ anyOf: [ // [!code ++]
+ { // [!code ++]
+ selector: 'type', // [!code ++]
+ elementNamePattern: 'Output' // [!code ++]
+ }, // [!code ++]
+ { // [!code ++]
+ selector: 'interface', // [!code ++]
+ elementNamePattern: 'Output' // [!code ++]
+ }, // [!code ++]
+ ] // [!code ++]
+ }, // [!code ++]
+ { // [!code ++]
+ groupName: 'unsorted-functions', // [!code ++]
+ type: 'unsorted', // [!code ++]
+ selector: 'function', // [!code ++]
+ }, // [!code ++]
+ ] // [!code ++]
+ anyOf: [ // [!code ++]
+ { // [!code ++]
+ selector: 'type', // [!code ++]
+ elementNamePattern: 'Output' // [!code ++]
+ }, // [!code ++]
+ { // [!code ++]
+ selector: 'interface', // [!code ++]
+ elementNamePattern: 'Output' // [!code ++]
+ }, // [!code ++]
+ ] // [!code ++]
+ }, // [!code ++]
+ { // [!code ++]
+ groupName: 'unsorted-functions', // [!code ++]
+ type: 'unsorted', // [!code ++]
+ selector: 'function', // [!code ++]
+ }, // [!code ++]
+ ] // [!code ++]
}
```

Expand Down
26 changes: 13 additions & 13 deletions docs/content/rules/sort-object-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -506,22 +506,22 @@ type User = {
```js
{
groups: [
+ 'top', // [!code ++]
+ 'top', // [!code ++]
'unknown',
+ ['optional-multiline-member', 'bottom'] // [!code ++]
],
+ customGroups: [ // [!code ++]
+ { // [!code ++]
+ groupName: 'top', // [!code ++]
+ selector: 'property', // [!code ++]
+ elementNamePattern: '^(?:id|name)$', // [!code ++]
+ }, // [!code ++]
+ { // [!code ++]
+ groupName: 'bottom', // [!code ++]
+ selector: 'property', // [!code ++]
+ elementNamePattern: '.+_metadata$', // [!code ++]
+ } // [!code ++]
+ ] // [!code ++]
+ customGroups: [ // [!code ++]
+ { // [!code ++]
+ groupName: 'top', // [!code ++]
+ selector: 'property', // [!code ++]
+ elementNamePattern: '^(?:id|name)$', // [!code ++]
+ }, // [!code ++]
+ { // [!code ++]
+ groupName: 'bottom', // [!code ++]
+ selector: 'property', // [!code ++]
+ elementNamePattern: '.+_metadata$', // [!code ++]
+ } // [!code ++]
+ ] // [!code ++]
}
```
Expand Down
16 changes: 8 additions & 8 deletions docs/content/rules/sort-objects.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -421,15 +421,15 @@ const user = {
```js
{
groups: [
+ 'top', // [!code ++]
['multiline', 'method'], // [!code ++]
['unknown'], // [!code ++]
'bottom' // [!code ++]
+ 'top', // [!code ++]
['multiline', 'method'], // [!code ++]
['unknown'], // [!code ++]
'bottom' // [!code ++]
],
+ customGroups: { // [!code ++]
+ top: ['^id$', '^name$'] // [!code ++]
+ bottom: '.+_metadata$' // [!code ++]
+ } // [!code ++]
+ customGroups: { // [!code ++]
+ top: ['^id$', '^name$'] // [!code ++]
+ bottom: '.+_metadata$' // [!code ++]
+ } // [!code ++]
}
```

Expand Down
36 changes: 25 additions & 11 deletions rules/sort-classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,14 @@ export default createEslintRule<SortClassesOptions, MESSAGE_ID>({
member.type === 'MethodDefinition' ||
member.type === 'TSAbstractMethodDefinition'
) {
// By putting the static modifier before accessibility modifiers,
// We prioritize 'static' over those in cases like:
// Config: ['static-method', 'public-method']
// Element: public static method();
// Element will be classified as 'static-method' before 'public-method'
/**
* By putting the static modifier before accessibility modifiers, we
* prioritize 'static' over those in cases like:
* config: ['static-method', 'public-method']
* element: public static method();
* Element will be classified as 'static-method' before
* 'public-method'.
*/
if (member.static) {
modifiers.push('static')
}
Expand Down Expand Up @@ -437,9 +440,11 @@ export default createEslintRule<SortClassesOptions, MESSAGE_ID>({
}
selectors.push('accessor-property')
} else {
// Member is necessarily a Property
// Similarly to above for methods, prioritize 'static', 'declare', 'decorated', 'abstract', 'override' and 'readonly'
// Over accessibility modifiers
/**
* Member is necessarily a property similarly to above for methods,
* prioritize 'static', 'declare', 'decorated', 'abstract',
* 'override' and 'readonly' over accessibility modifiers.
*/
if (member.static) {
modifiers.push('static')
}
Expand Down Expand Up @@ -514,15 +519,24 @@ export default createEslintRule<SortClassesOptions, MESSAGE_ID>({
})
) {
defineGroup(customGroup.groupName, true)
// If the custom group is not referenced in the `groups` option, it will be ignored
/**
* If the custom group is not referenced in the `groups` option,
* it will be ignored.
*/
if (getGroup() === customGroup.groupName) {
break
}
}
}

// Members belonging to the same overload signature group should have the same size in order to keep line-length sorting between them consistent.
// It is unclear what should be considered the size of an overload signature group. Take the size of the implementation by default.
/**
* Members belonging to the same overload signature group should have
* the same size in order to keep line-length sorting between them
* consistent.
*
* It is unclear what should be considered the size of an overload
* signature group. Take the size of the implementation by default.
*/
let overloadSignatureGroupMember = overloadSignatureGroups
.find(overloadSignatures => overloadSignatures.includes(member))
?.at(-1)
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-classes/does-custom-group-match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export let doesCustomGroupMatch = (
props: DoesCustomGroupMatchProps,
): boolean => {
if ('anyOf' in props.customGroup) {
// At least one subgroup must match
// At least one subgroup must match.
return props.customGroup.anyOf.some(subgroup =>
doesCustomGroupMatch({ ...props, customGroup: subgroup }),
)
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
)

let compareOptions: CompareOptions<SortEnumsSortingNode> = {
// Get the enum value rather than the name if needed
// Get the enum value rather than the name if needed.
nodeValueGetter:
options.sortByValue || (isNumericEnum && options.forceNumericSort)
? sortingNode => {
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
typescriptImport.sys,
tsConfigOutput.cache,
)
// If the module can't be resolved, assume it is external
// If the module can't be resolved, assume it is external.
if (
typeof resolution.resolvedModule?.isExternalLibraryImport !==
'boolean'
Expand Down
7 changes: 5 additions & 2 deletions rules/sort-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ let analyzeModule = ({
modifiers.includes('export') &&
modifiers.includes('decorated')
) {
// Not always handled correctly at the moment
// Not always handled correctly at the moment.
continue
}

Expand All @@ -333,7 +333,10 @@ let analyzeModule = ({
})
) {
defineGroup(customGroup.groupName, true)
// If the custom group is not referenced in the `groups` option, it will be ignored
/**
* If the custom group is not referenced in the `groups` option, it will
* be ignored
*/
if (getGroup() === customGroup.groupName) {
break
}
Expand Down
Loading

0 comments on commit b13976d

Please sign in to comment.