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

Commit 27d6780

Browse files
authored
Merge pull request #258 from crispthinking/strict-option
add `strict` option
2 parents 9293945 + d69ed56 commit 27d6780

File tree

4 files changed

+67
-2
lines changed

4 files changed

+67
-2
lines changed

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const sourceMapsCorrections = {}
1313
const errorWasThrown = {}
1414
const DEFAULT_OPTIONS = {
1515
moduleName: 'styled-components',
16-
importName: 'default'
16+
importName: 'default',
17+
strict: false
1718
}
1819

1920
module.exports = options => ({

src/parsers/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ const processStyledComponentsFile = (ast, absolutePath, options) => {
4444
importedNames = parseImports(node)
4545
return
4646
}
47-
const helper = isHelper(node, importedNames)
47+
const helper = !options.strict
48+
? isHelper(node, importedNames)
49+
: isHelper(node, [importedNames[options.importName]])
4850
const processedNode = Object.assign({}, node)
4951
if (hasAttrsCall(node)) {
5052
processedNode.tag = getAttrsObject(node)

test/fixtures/options/strict.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { foo, bar } from 'some-module'
2+
3+
// EMPTY BLOCK
4+
const Button = foo`
5+
6+
`;
7+
const Button2 = bar`
8+
9+
`;

test/options.test.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,57 @@ describe('options', () => {
231231
expect(data.results[0].errored).toEqual(undefined)
232232
})
233233
})
234+
235+
describe('strict', () => {
236+
beforeEach(done => {
237+
fixture = path.join(__dirname, './fixtures/options/strict.js')
238+
239+
stylelint
240+
.lint({
241+
files: [fixture],
242+
config: {
243+
processors: [
244+
[
245+
processor,
246+
{
247+
moduleName: 'some-module',
248+
importName: 'foo',
249+
strict: true
250+
}
251+
]
252+
],
253+
rules
254+
}
255+
})
256+
.then(result => {
257+
data = result
258+
done()
259+
})
260+
.catch(err => {
261+
console.log(err)
262+
data = err
263+
done()
264+
})
265+
})
266+
267+
it('should have one result', () => {
268+
expect(data.results.length).toEqual(1)
269+
})
270+
271+
it('should use the right file', () => {
272+
expect(data.results[0].source).toEqual(fixture)
273+
})
274+
275+
it('should have errored', () => {
276+
expect(data.results[0].errored).toEqual(true)
277+
})
278+
279+
it('should have one warning (i.e. wrong lines of code)', () => {
280+
expect(data.results[0].warnings.length).toEqual(1)
281+
})
282+
283+
it('should have a block-no-empty as the first warning', () => {
284+
expect(data.results[0].warnings[0].rule).toEqual('block-no-empty')
285+
})
286+
})
234287
})

0 commit comments

Comments
 (0)