Bluesky app fork with some witchin' additions 💫 witchsky.app
bluesky fork

Add eslint rule to fix imports without the `#/` path alias (#5175)

authored by samuel.fm and committed by GitHub f42d4411 22410a3c

+1
.eslintrc.js
··· 33 33 ], 34 34 'bsky-internal/use-exact-imports': 'error', 35 35 'bsky-internal/use-typed-gates': 'error', 36 + 'bsky-internal/use-prefixed-imports': 'warn', 36 37 'simple-import-sort/imports': [ 37 38 'warn', 38 39 {
+1
eslint/index.js
··· 5 5 'avoid-unwrapped-text': require('./avoid-unwrapped-text'), 6 6 'use-exact-imports': require('./use-exact-imports'), 7 7 'use-typed-gates': require('./use-typed-gates'), 8 + 'use-prefixed-imports': require('./use-prefixed-imports'), 8 9 }, 9 10 }
+4 -4
eslint/use-exact-imports.js
··· 1 - /* eslint-disable bsky-internal/use-exact-imports */ 2 1 const BANNED_IMPORTS = [ 3 2 '@fortawesome/free-regular-svg-icons', 4 3 '@fortawesome/free-solid-svg-icons', ··· 6 5 7 6 exports.create = function create(context) { 8 7 return { 9 - Literal(node) { 10 - if (typeof node.value !== 'string') { 8 + ImportDeclaration(node) { 9 + const source = node.source 10 + if (typeof source.value !== 'string') { 11 11 return 12 12 } 13 - if (BANNED_IMPORTS.includes(node.value)) { 13 + if (BANNED_IMPORTS.includes(source.value)) { 14 14 context.report({ 15 15 node, 16 16 message:
+39
eslint/use-prefixed-imports.js
··· 1 + const BANNED_IMPORT_PREFIXES = [ 2 + 'alf/', 3 + 'components/', 4 + 'lib/', 5 + 'locale/', 6 + 'logger/', 7 + 'platform/', 8 + 'state/', 9 + 'storage/', 10 + 'view/', 11 + ] 12 + 13 + module.exports = { 14 + meta: { 15 + type: 'suggestion', 16 + fixable: 'code', 17 + }, 18 + create(context) { 19 + return { 20 + ImportDeclaration(node) { 21 + const source = node.source 22 + if (typeof source.value !== 'string') { 23 + return 24 + } 25 + if ( 26 + BANNED_IMPORT_PREFIXES.some(banned => source.value.startsWith(banned)) 27 + ) { 28 + context.report({ 29 + node: source, 30 + message: `Use '#/${source.value}'`, 31 + fix(fixer) { 32 + return fixer.replaceText(source, `'#/${source.value}'`) 33 + }, 34 + }) 35 + } 36 + }, 37 + } 38 + }, 39 + }