Skip to content

Commit

Permalink
fix(sort-modules): check if node is sortable
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Nov 25, 2024
1 parent 5e01924 commit 26e2195
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
20 changes: 12 additions & 8 deletions rules/sort-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { TSESTree } from '@typescript-eslint/types'
import type { TSESLint } from '@typescript-eslint/utils'

import { AST_NODE_TYPES } from '@typescript-eslint/utils'
import { isSortable } from 'utils/is-sortable'

This comment has been minimized.

Copy link
@SStranks

SStranks Nov 25, 2024

This import statement isn't pathed correctly, eslint is throwing 'cannot find module'

This comment has been minimized.

Copy link
@azat-io

azat-io Nov 25, 2024

Author Owner

My bad. Fixed in v4.1.2.


import type {
SortModulesOptions,
Expand Down Expand Up @@ -192,14 +193,17 @@ export default createEslintRule<SortModulesOptions, MESSAGE_ID>({
})

return {
Program: program =>
analyzeModule({
eslintDisabledLines,
sourceCode,
options,
program,
context,
}),
Program: program => {
if (isSortable(program.body)) {
return analyzeModule({
eslintDisabledLines,
sourceCode,
options,
program,
context,
})
}
},
}
},
defaultOptions: [defaultOptions],
Expand Down
3 changes: 2 additions & 1 deletion utils/is-sortable.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export let isSortable = (array: unknown[]): boolean => array.length > 1
export let isSortable = (node: unknown): boolean =>
Array.isArray(node) && node.length > 1

0 comments on commit 26e2195

Please sign in to comment.