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

add strict option #258

Merged
merged 2 commits into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
})
})
})