Skip to content

Commit 3b81adf

Browse files
authored
Merge pull request #2 from vvozvv/bugfix/fix-non-correct-rule
Bugfix/fix non correct rule
2 parents 1dba878 + 57f75b1 commit 3b81adf

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# eslint-plugin-styled-component
2+
Optimization of imports for style files specified via **.styled postfix
3+
4+
## Installation
5+
6+
```sh
7+
npm install eslint-plugin-styled-component-import --save-dev
8+
```
9+
10+
## Usage
11+
12+
```json
13+
{
14+
"plugins": [
15+
"styled-component-import"
16+
]
17+
}
18+
```
19+
20+
You can add rules:
21+
22+
```json
23+
{
24+
"rules": {
25+
"styled-component-import/non-correct-import": 2
26+
}
27+
}
28+
```

lib/rules/non-correct-import.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,24 @@ module.exports = {
22
meta: {
33
type: 'problem',
44
hasSuggestions: true,
5-
fixable: true,
5+
docs: {
6+
description: "All style components files must be imported via a single variable",
7+
},
8+
fixable: false,
69
},
710
create(context) {
811
return {
912
ImportDeclaration(node) {
10-
const pathArray = node.source.raw.substr(1, node.source.raw.length - 2);
11-
console.log(node, node.specifiers[0].type)
13+
const pathArray = node.source.raw.substr(1, node.source.raw.length - 2).split('.');
1214

1315
if (
1416
pathArray.includes('styled') &&
1517
node.specifiers[0].type !== 'ImportNamespaceSpecifier'
1618
) {
17-
console.log('error')
1819

1920
return context.report({
2021
node: node,
21-
message: 'Неправильный импорт. Измените на * as S',
22-
fix(fixer){
23-
return [fixer.replaceTextRange([node.start, node.end], `import * as S from ${node.source.raw}`)]
24-
}
22+
message: 'Incorrect import for the styled file. Replace with import in one variable * as',
2523
})
2624
}
2725
}

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "eslint-plugin-styled-component-import",
33
"private": false,
4-
"version": "1.0.1",
4+
"version": "1.0.2",
55
"description": "",
66
"keywords": [
77
"eslint",

0 commit comments

Comments
 (0)