Skip to content

Commit 31884b2

Browse files
author
avazhov
committedSep 6, 2023
init rule
1 parent 7bbc029 commit 31884b2

7 files changed

+79
-4
lines changed
 

‎.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 2
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

‎.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

‎LICENSE-MIT

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Aleksei Vazhov, contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎README.MD

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# eslint-plugin-styled-component-import
2+
3+
Плагин для импорта styled-component из файлов .styled/.styles

‎lib/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
rules: {
3+
'non-correct-import': require('./rules/non-correct-import.js'),
4+
},
5+
};

‎lib/rules/non-correct-import.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module.exports = {
2+
meta: {
3+
type: 'problem',
4+
hasSuggestions: true,
5+
fixable: true,
6+
},
7+
create(context) {
8+
return {
9+
ImportDeclaration(node) {
10+
const pathArray = node.source.raw.substr(1, node.source.raw.length - 2);
11+
console.log(node, node.specifiers[0].type)
12+
13+
if (
14+
pathArray.includes('styled') &&
15+
node.specifiers[0].type !== 'ImportNamespaceSpecifier'
16+
) {
17+
console.log('error')
18+
19+
return context.report({
20+
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+
}
25+
})
26+
}
27+
}
28+
};
29+
},
30+
};

‎package.json

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
{
2-
"name": "eslint-plugin-styled-component",
2+
"name": "eslint-plugin-styled-component-import",
3+
"private": false,
34
"version": "1.0.0",
45
"description": "",
5-
"main": "index.js",
6+
"keywords": [
7+
"eslint",
8+
"eslintplugin",
9+
"eslint-plugin"
10+
],
11+
"author": "vvozvv",
12+
"license": "ISC",
13+
"main": "lib/index.js",
614
"scripts": {
715
"test": "echo \"Error: no test specified\" && exit 1"
816
},
917
"repository": {
1018
"type": "git",
1119
"url": "git+ssh://git@github.com/vvozvv/eslint-plugin-styled-component.git"
1220
},
13-
"author": "vvozvv",
14-
"license": "ISC",
1521
"bugs": {
1622
"url": "https://github.com/vvozvv/eslint-plugin-styled-component/issues"
1723
},

0 commit comments

Comments
 (0)