-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate
@emotion/eslint-plugin
to TypeScript (#2568)
* feat(eslint-plugin): add standard utils & dependencies for typescript * feat(eslint-plugin): convert `no-vanilla` to typescript * feat(eslint-plugin): convert `styled-import` to typescript * feat(eslint-plugin): convert `import-from-emotion` to typescript * feat(eslint-plugin): convert `syntax-preference` to typescript * feat(eslint-plugin): convert `pkg-renaming` to typescript * feat(eslint-plugin): convert `jsx-import` to typescript * feat(eslint-plugin): move index to typescript * feat(eslint-plugin): add changeset * fix(eslint-plugin): use `require` to get package version * fix(eslint-plugin): adjust rule description Co-authored-by: Sam Magura <srmagura@gmail.com> * fix(eslint-plugin): use `REPO_URL` constant everywhere * chore(eslint-plugin): add change sets for other bugs * nit * Tweak changeset * Report empty css attribute as invalid in syntax-preference rule * Tweak changesets Co-authored-by: Sam Magura <srmagura@gmail.com> Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
- Loading branch information
1 parent
f99981b
commit 304f7e3
Showing
25 changed files
with
616 additions
and
347 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@emotion/eslint-plugin': patch | ||
--- | ||
|
||
An empty css prop (`<div css />`) will now raise an error in the `@emotion/syntax-preference` rule instead of crashing on this case. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@emotion/eslint-plugin': minor | ||
--- | ||
|
||
Source code has been migrated to TypeScript. From now on type declarations will be emitted based on that, instead of being hand-written. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@emotion/eslint-plugin': patch | ||
--- | ||
|
||
Fixed a crash on empty css prop (`<div css />`) in the `@emotion/jsx-import` rule. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/experimental-utils' | ||
import { createRule } from '../utils' | ||
|
||
export default createRule({ | ||
name: __filename, | ||
meta: { | ||
docs: { | ||
category: 'Best Practices', | ||
description: 'Ensure styled is imported from @emotion/styled', | ||
recommended: false | ||
}, | ||
fixable: 'code', | ||
messages: { | ||
incorrectImport: `emotion's exports should be imported directly from emotion rather than from react-emotion` | ||
}, | ||
schema: [], | ||
type: 'problem' | ||
}, | ||
defaultOptions: [], | ||
create(context) { | ||
return { | ||
ImportDeclaration(node) { | ||
if ( | ||
node.source.value === 'react-emotion' && | ||
node.specifiers.some( | ||
x => x.type !== AST_NODE_TYPES.ImportDefaultSpecifier | ||
) | ||
) { | ||
context.report({ | ||
node: node.source, | ||
messageId: 'incorrectImport', | ||
fix(fixer) { | ||
if ( | ||
node.specifiers[0].type === | ||
AST_NODE_TYPES.ImportNamespaceSpecifier | ||
) { | ||
return null | ||
} | ||
// default specifiers are always first | ||
if ( | ||
node.specifiers[0].type === | ||
AST_NODE_TYPES.ImportDefaultSpecifier | ||
) { | ||
return fixer.replaceText( | ||
node, | ||
`import ${ | ||
node.specifiers[0].local.name | ||
} from '@emotion/styled';\nimport { ${node.specifiers | ||
.filter( | ||
(x): x is TSESTree.ImportSpecifier => | ||
x.type === AST_NODE_TYPES.ImportSpecifier | ||
) | ||
.map(x => | ||
x.local.name === x.imported.name | ||
? x.local.name | ||
: `${x.imported.name} as ${x.local.name}` | ||
) | ||
.join(', ')} } from 'emotion';` | ||
) | ||
} | ||
return fixer.replaceText(node.source, "'emotion'") | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.