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!: add import sorting rule #126

Merged
merged 3 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions js.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = {
},
plugins: [
'no-only-tests',
'jsdoc'
'jsdoc',
'import'
],
rules: {
strict: ['error', 'safe'],
Expand Down Expand Up @@ -73,8 +74,46 @@ module.exports = {
// parse various forms correctly. For now warn on invalid type froms,
// should revisit once following issue is fixed:
// https://github.com/jsdoctypeparser/jsdoctypeparser/issues/50
'jsdoc/valid-types': 'off'

'jsdoc/valid-types': 'off',
'import/order': [
'error',
{
alphabetize: {
order: 'asc',
caseInsensitive: false
},
'newlines-between': 'always',
// the overall order of imports
groups: ['builtin', 'external', 'internal', ['sibling', 'parent', 'index'], 'object'],
pathGroupsExcludedImportTypes: ['builtin'],
pathGroups: [
{ // 3p imports
pattern: '+(!(@))*/**',
group: 'external',
position: 'before',
patternOptions: { nonegate: true }
},
{ // scoped external imports excluding our 2p scoped packages
pattern: '@!(ipfs|libp2p|ipfs-shipyard|ipld|multiformats)/**',
group: 'external',
position: 'after',
patternOptions: { nonegate: false }
},
{ // our 2p scoped packages
pattern: '@{ipfs,libp2p,ipfs-shipyard,ipld,multiformats}/**',
group: 'parent',
position: 'before',
patternOptions: { nonegate: true }
},
{ // our relative (this package) imports
pattern: '.*/**',
group: 'index',
position: 'after',
patternOptions: { dot: true, nonegate: true }
}
]
}
]
achingbrain marked this conversation as resolved.
Show resolved Hide resolved
},
settings: {
jsdoc: {
Expand Down
44 changes: 42 additions & 2 deletions ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ module.exports = {
'standard-with-typescript'
],
plugins: [
'etc'
'etc',
'import'
achingbrain marked this conversation as resolved.
Show resolved Hide resolved
],
rules: {
'no-use-before-define': 'off', // Types often are recursive & no use before define is too restrictive
Expand All @@ -22,6 +23,45 @@ module.exports = {
'@typescript-eslint/await-thenable': 'error', // disallows awaiting a value that is not a "Thenable"
'@typescript-eslint/restrict-template-expressions': 'off', // allow values with `any` type in template literals
'jsdoc/require-param': 'off', // do not require jsdoc for params
'jsdoc/require-param-type': 'off' // allow compiler to derive param type
'jsdoc/require-param-type': 'off', // allow compiler to derive param type
'import/order': [ // sort imports
'error',
{
alphabetize: {
order: 'asc',
caseInsensitive: false
},
'newlines-between': 'always',
// the overall order of imports
groups: ['builtin', 'external', 'internal', ['sibling', 'parent', 'index'], 'object'],
pathGroupsExcludedImportTypes: ['builtin'],
pathGroups: [
{ // 3p imports
pattern: '+(!(@))*/**',
group: 'external',
position: 'before',
patternOptions: { nonegate: true }
},
{ // scoped external imports excluding our 2p scoped packages
pattern: '@!(ipfs|libp2p|ipfs-shipyard|ipld|multiformats)/**',
group: 'external',
position: 'after',
patternOptions: { nonegate: false }
},
{ // our 2p scoped packages
pattern: '@{ipfs,libp2p,ipfs-shipyard,ipld,multiformats}/**',
group: 'parent',
position: 'before',
patternOptions: { nonegate: true }
},
{ // our relative (this package) imports
pattern: '.*/**',
group: 'index',
position: 'after',
patternOptions: { dot: true, nonegate: true }
}
]
}
]
achingbrain marked this conversation as resolved.
Show resolved Hide resolved
}
}