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

Commit

Permalink
Merge pull request #258 from crispthinking/strict-option
Browse files Browse the repository at this point in the history
add `strict` option
  • Loading branch information
chinesedfan authored Mar 26, 2019
2 parents 9293945 + d69ed56 commit 27d6780
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const sourceMapsCorrections = {}
const errorWasThrown = {}
const DEFAULT_OPTIONS = {
moduleName: 'styled-components',
importName: 'default'
importName: 'default',
strict: false
}

module.exports = options => ({
Expand Down
4 changes: 3 additions & 1 deletion src/parsers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ const processStyledComponentsFile = (ast, absolutePath, options) => {
importedNames = parseImports(node)
return
}
const helper = isHelper(node, importedNames)
const helper = !options.strict
? isHelper(node, importedNames)
: isHelper(node, [importedNames[options.importName]])
const processedNode = Object.assign({}, node)
if (hasAttrsCall(node)) {
processedNode.tag = getAttrsObject(node)
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/options/strict.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { foo, bar } from 'some-module'

// EMPTY BLOCK
const Button = foo`
`;
const Button2 = bar`
`;
53 changes: 53 additions & 0 deletions test/options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,57 @@ describe('options', () => {
expect(data.results[0].errored).toEqual(undefined)
})
})

describe('strict', () => {
beforeEach(done => {
fixture = path.join(__dirname, './fixtures/options/strict.js')

stylelint
.lint({
files: [fixture],
config: {
processors: [
[
processor,
{
moduleName: 'some-module',
importName: 'foo',
strict: true
}
]
],
rules
}
})
.then(result => {
data = result
done()
})
.catch(err => {
console.log(err)
data = err
done()
})
})

it('should have one result', () => {
expect(data.results.length).toEqual(1)
})

it('should use the right file', () => {
expect(data.results[0].source).toEqual(fixture)
})

it('should have errored', () => {
expect(data.results[0].errored).toEqual(true)
})

it('should have one warning (i.e. wrong lines of code)', () => {
expect(data.results[0].warnings.length).toEqual(1)
})

it('should have a block-no-empty as the first warning', () => {
expect(data.results[0].warnings[0].rule).toEqual('block-no-empty')
})
})
})

0 comments on commit 27d6780

Please sign in to comment.