Skip to content

Commit

Permalink
Automatically remove trailing .js from @shopify/cli-kit imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkham committed Jan 27, 2023
1 parent afe5415 commit 4771adc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ module.exports = {
'rulesdir/command-reserved-flags': 'error',
'rulesdir/no-error-factory-functions': 'error',
'rulesdir/no-process-cwd': 'error',
'rulesdir/no-trailing-js-in-cli-kit-imports': 'error',
'no-restricted-syntax': [
'error',
{
Expand Down
30 changes: 30 additions & 0 deletions eslint-rules/no-trailing-js-in-cli-kit-imports.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Remove trailing .js when importing from @shopify/cli-kit',
},
fixable: 'code',
schema: [],
messages: {
noTrailingJsInCliKit: 'Trailing .js is not needed when importing from @shopify/cli-kit',
},
},

create(context) {
return {
ImportDeclaration(node) {
const source = node.source.value
if (source.startsWith('@shopify/cli-kit') && source.endsWith('.js')) {
context.report({
node,
messageId: 'noTrailingJsInCliKit',
fix: function (fixer) {
return fixer.replaceText(node.source, `'${source.slice(0, -3)}'`)
},
})
}
},
}
},
}

0 comments on commit 4771adc

Please sign in to comment.