Skip to content

Commit 8dbcce5

Browse files
committed
chore: Add linting
1 parent d233c6c commit 8dbcce5

File tree

6 files changed

+1201
-44
lines changed

6 files changed

+1201
-44
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/node_modules/**
2+
**/lib/**
3+
test/fixtures/**

.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: 'davesnx-rules'
3+
}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
"build": "babel src -d lib",
1515
"test": "mocha --compilers js:babel-register",
1616
"test:watch": "yarn test -- --watch",
17+
"lint": "eslint .",
1718
"prepublishOnly": "yarn clean && yarn build",
1819
"semantic-release": "semantic-release",
1920
"travis-deploy-once": "travis-deploy-once"
2021
},
2122
"dependencies": {
23+
"eslint-config-davesnx-rules": "^1.0.0",
2224
"lodash.camelcase": "^4.3.0",
2325
"lodash.isstring": "^4.0.1",
2426
"lodash.kebabcase": "^4.1.1",
@@ -55,6 +57,7 @@
5557
],
5658
"husky": {
5759
"hooks": {
60+
"pre-commit": "npm run lint",
5861
"pre-push": "npm run test"
5962
}
6063
}

src/index.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import checkValidOptions from './options'
22
import TaggedTemplateExpression from './styled-components'
33

4-
function isReactFragment (openingElement) {
4+
function isReactFragment(openingElement) {
55
return (
66
openingElement.node.name.name === 'Fragment' ||
77
(openingElement.node.name.type === 'JSXMemberExpression' &&
88
openingElement.node.name.object.name === 'React' &&
99
openingElement.node.name.property.name === 'Fragment')
10-
);
10+
)
1111
}
1212

13-
function functionBodyPushAttributes (t, path, options, componentName) {
13+
function functionBodyPushAttributes(t, path, options, componentName) {
1414
let openingElement = null
1515
const functionBody = path.get('body').get('body')
1616
if (functionBody.parent && functionBody.parent.type === 'JSXElement') {
17-
const jsxElement = functionBody.find((c) => {
17+
const jsxElement = functionBody.find(c => {
1818
return c.type === 'JSXElement'
1919
})
2020
if (!jsxElement) return
2121
openingElement = jsxElement.get('openingElement')
2222
} else {
23-
const returnStatement = functionBody.find((c) => {
23+
const returnStatement = functionBody.find(c => {
2424
return c.type === 'ReturnStatement'
2525
})
2626
if (!returnStatement) return
@@ -42,30 +42,30 @@ function functionBodyPushAttributes (t, path, options, componentName) {
4242
)
4343
}
4444

45-
export default function ({types: t}) {
45+
export default function({ types: t }) {
4646
return {
4747
visitor: {
4848
TaggedTemplateExpression,
49-
FunctionDeclaration (path, state) {
50-
if (!path.node.id || !path.node.id.name) return;
49+
FunctionDeclaration(path, state) {
50+
if (!path.node.id || !path.node.id.name) return
5151

5252
const options = checkValidOptions(state)
5353
const componentName = path.node.id.name
5454

5555
functionBodyPushAttributes(t, path, options, componentName)
5656
},
57-
ArrowFunctionExpression (path, state) {
57+
ArrowFunctionExpression(path, state) {
5858
const options = checkValidOptions(state)
5959
if (!path.parent.id || !path.parent.id.name) return
6060
const componentName = path.parent.id.name
6161

6262
functionBodyPushAttributes(t, path, options, componentName)
6363
},
64-
ClassDeclaration (path, state) {
65-
let name = path.get('id')
66-
let properties = path.get('body').get('body')
64+
ClassDeclaration(path, state) {
65+
const name = path.get('id')
66+
const properties = path.get('body').get('body')
6767

68-
let render = properties.find(prop => {
68+
const render = properties.find(prop => {
6969
return (
7070
prop.isClassMethod() &&
7171
prop.get('key').isIdentifier({ name: 'render' })
@@ -79,7 +79,7 @@ export default function ({types: t}) {
7979
const options = checkValidOptions(state)
8080

8181
render.traverse({
82-
ReturnStatement (returnStatement) {
82+
ReturnStatement(returnStatement) {
8383
const arg = returnStatement.get('argument')
8484
if (!arg.isJSXElement()) return
8585

src/styled-components.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ export default function TaggedTemplateExpression(path, state) {
3131
}
3232
} catch (e) {}
3333

34-
return
35-
3634
// hoisted helpers in closure
3735
function insertBefore(node, id) {
3836
return t.callExpression(t.memberExpression(node, t.identifier('attrs')), [
3937
t.objectExpression([
40-
t.objectProperty(t.StringLiteral(options.attribute), t.StringLiteral(options.format(id)))
38+
t.objectProperty(
39+
t.StringLiteral(options.attribute),
40+
t.StringLiteral(options.format(id))
41+
)
4142
])
4243
])
4344
}
@@ -51,7 +52,7 @@ export default function TaggedTemplateExpression(path, state) {
5152
if (!t.isIdentifier(node)) return false
5253
const binding = scope.getBinding(node.name)
5354
if (!binding || binding.kind !== 'module') return false
54-
return binding.path.parent.source.value == 'styled-components'
55+
return binding.path.parent.source.value === 'styled-components'
5556
}
5657
}
5758
function getIdFrom(parentPath) {

0 commit comments

Comments
 (0)