Add eslint rule to fix imports without the #/
path alias (#5175)
This commit is contained in:
parent
22410a3cee
commit
f42d44112d
@ -33,6 +33,7 @@ module.exports = {
|
|||||||
],
|
],
|
||||||
'bsky-internal/use-exact-imports': 'error',
|
'bsky-internal/use-exact-imports': 'error',
|
||||||
'bsky-internal/use-typed-gates': 'error',
|
'bsky-internal/use-typed-gates': 'error',
|
||||||
|
'bsky-internal/use-prefixed-imports': 'warn',
|
||||||
'simple-import-sort/imports': [
|
'simple-import-sort/imports': [
|
||||||
'warn',
|
'warn',
|
||||||
{
|
{
|
||||||
|
@ -5,5 +5,6 @@ module.exports = {
|
|||||||
'avoid-unwrapped-text': require('./avoid-unwrapped-text'),
|
'avoid-unwrapped-text': require('./avoid-unwrapped-text'),
|
||||||
'use-exact-imports': require('./use-exact-imports'),
|
'use-exact-imports': require('./use-exact-imports'),
|
||||||
'use-typed-gates': require('./use-typed-gates'),
|
'use-typed-gates': require('./use-typed-gates'),
|
||||||
|
'use-prefixed-imports': require('./use-prefixed-imports'),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
/* eslint-disable bsky-internal/use-exact-imports */
|
|
||||||
const BANNED_IMPORTS = [
|
const BANNED_IMPORTS = [
|
||||||
'@fortawesome/free-regular-svg-icons',
|
'@fortawesome/free-regular-svg-icons',
|
||||||
'@fortawesome/free-solid-svg-icons',
|
'@fortawesome/free-solid-svg-icons',
|
||||||
@ -6,11 +5,12 @@ const BANNED_IMPORTS = [
|
|||||||
|
|
||||||
exports.create = function create(context) {
|
exports.create = function create(context) {
|
||||||
return {
|
return {
|
||||||
Literal(node) {
|
ImportDeclaration(node) {
|
||||||
if (typeof node.value !== 'string') {
|
const source = node.source
|
||||||
|
if (typeof source.value !== 'string') {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (BANNED_IMPORTS.includes(node.value)) {
|
if (BANNED_IMPORTS.includes(source.value)) {
|
||||||
context.report({
|
context.report({
|
||||||
node,
|
node,
|
||||||
message:
|
message:
|
||||||
|
39
eslint/use-prefixed-imports.js
Normal file
39
eslint/use-prefixed-imports.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
const BANNED_IMPORT_PREFIXES = [
|
||||||
|
'alf/',
|
||||||
|
'components/',
|
||||||
|
'lib/',
|
||||||
|
'locale/',
|
||||||
|
'logger/',
|
||||||
|
'platform/',
|
||||||
|
'state/',
|
||||||
|
'storage/',
|
||||||
|
'view/',
|
||||||
|
]
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
meta: {
|
||||||
|
type: 'suggestion',
|
||||||
|
fixable: 'code',
|
||||||
|
},
|
||||||
|
create(context) {
|
||||||
|
return {
|
||||||
|
ImportDeclaration(node) {
|
||||||
|
const source = node.source
|
||||||
|
if (typeof source.value !== 'string') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
BANNED_IMPORT_PREFIXES.some(banned => source.value.startsWith(banned))
|
||||||
|
) {
|
||||||
|
context.report({
|
||||||
|
node: source,
|
||||||
|
message: `Use '#/${source.value}'`,
|
||||||
|
fix(fixer) {
|
||||||
|
return fixer.replaceText(source, `'#/${source.value}'`)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user