Skip to content
This repository was archived by the owner on May 14, 2021. It is now read-only.

Commit 7dbacd3

Browse files
feat: add support for multiple moduleName
1 parent cc685cc commit 7dbacd3

File tree

4 files changed

+103
-1
lines changed

4 files changed

+103
-1
lines changed

src/utils/styled.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const { isTaggedTemplateLiteral } = require('./tagged-template-literal')
55
* Check if something is a styled-components import declaration
66
*/
77
const isStyledImport = (node, moduleName) =>
8-
node.type === 'ImportDeclaration' && path.basename(node.source.value) === moduleName
8+
node.type === 'ImportDeclaration' &&
9+
(Array.isArray(moduleName) ? moduleName : [moduleName]).includes(path.basename(node.source.value))
910

1011
/**
1112
* Check if something is a styled shorthand call
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import emotion from 'some-module'
2+
3+
// ⚠️ EMPTY BLOCK ⚠️
4+
const Button = emotion.div`
5+
6+
`
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import emotion from '../../some-module'
2+
3+
// ⚠️ EMPTY BLOCK ⚠️
4+
const Button = emotion.div`
5+
6+
`

test/options.test.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const rules = {
1818

1919
describe('options', () => {
2020
let fixture
21+
let fixtures
2122
let data
2223

2324
describe('moduleName', () => {
@@ -116,6 +117,94 @@ describe('options', () => {
116117
})
117118
})
118119

120+
describe('moduleName array', () => {
121+
beforeEach(done => {
122+
stylelint
123+
.lint({
124+
files: fixtures,
125+
config: {
126+
// Set moduleName option to "emotion"
127+
processors: [[processor, { moduleName: ['emotion', 'some-module'] }]],
128+
rules
129+
}
130+
})
131+
.then(result => {
132+
data = result
133+
done()
134+
})
135+
.catch(err => {
136+
// eslint-disable-next-line no-console
137+
console.log(err)
138+
data = err
139+
done()
140+
})
141+
})
142+
143+
describe('moduleName', () => {
144+
beforeAll(() => {
145+
fixtures = [
146+
slash(path.join(__dirname, './fixtures/options/module-name.js')),
147+
slash(path.join(__dirname, './fixtures/options/module-name-two.js'))
148+
]
149+
})
150+
151+
it('should have one result', () => {
152+
expect(data.results.length).toEqual(2)
153+
})
154+
155+
it('should use the right file', () => {
156+
expect([slash(data.results[0].source), slash(data.results[1].source)]).toEqual(fixtures)
157+
})
158+
159+
it('should have errored', () => {
160+
expect([data.results[0].errored, data.results[1].errored]).toEqual([true, true])
161+
})
162+
163+
it('should have one warning (i.e. wrong lines of code)', () => {
164+
expect([data.results[0].warnings.length, data.results[1].warnings.length]).toEqual([1, 1])
165+
})
166+
167+
it('should have a block-no-empty as the first warning', () => {
168+
expect([data.results[0].warnings[0].rule, data.results[1].warnings[0].rule]).toEqual([
169+
'block-no-empty',
170+
'block-no-empty'
171+
])
172+
})
173+
})
174+
175+
describe('relative moduleName', () => {
176+
beforeAll(() => {
177+
fixtures = [
178+
slash(path.join(__dirname, './fixtures/options/relative-module-name.js')),
179+
slash(path.join(__dirname, './fixtures/options/relative-module-name-two.js'))
180+
]
181+
})
182+
183+
it('should have one result', () => {
184+
expect(data.results.length).toEqual(2)
185+
})
186+
187+
it('should use the right file', () => {
188+
expect([slash(data.results[0].source), slash(data.results[1].source)]).toEqual(fixtures)
189+
})
190+
191+
it('should have errored', () => {
192+
expect([data.results[0].errored, data.results[1].errored]).toEqual([true, true])
193+
})
194+
195+
it('should have one warning (i.e. wrong lines of code)', () => {
196+
expect([data.results[0].warnings.length, data.results[1].warnings.length]).toEqual([1, 1])
197+
})
198+
199+
it('should have a block-no-empty as the first warning', () => {
200+
expect([data.results[0].warnings[0].rule, data.results[1].warnings[0].rule]).toEqual([
201+
'block-no-empty',
202+
'block-no-empty'
203+
])
204+
})
205+
})
206+
})
207+
119208
describe('importName', () => {
120209
// NOTE beforeEach() runs _after_ the beforeAll() hooks of the describe() blocks, so `fixture`
121210
// will have the right path

0 commit comments

Comments
 (0)