Skip to content

Commit aa935f4

Browse files
committed
Merge pull request #43 from joshwnj/warn-about-invalid-rules
Emit warnings when multiple @value rules don't end in a semicolon
2 parents aa28589 + 59f14b2 commit aa935f4

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let options = {}
88
let importIndex = 0
99
let createImportedName = options && options.createImportedName || ((importName/*, path*/) => `i__const_${importName.replace(/\W/g, '_')}_${importIndex++}`)
1010

11-
export default css => {
11+
export default (css, result) => {
1212
let importAliases = []
1313
let definitions = {}
1414

@@ -49,6 +49,10 @@ export default css => {
4949
if (matchImports.exec(atRule.params)) {
5050
addImport(atRule)
5151
} else {
52+
if (atRule.params.indexOf('@value') !== -1) {
53+
result.warn('Invalid value definition: ' + atRule.params)
54+
}
55+
5256
addDefinition(atRule)
5357
}
5458
})

test/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ describe('constants', () => {
1919
test('@value red blue;', ':export {\n red: blue\n}')
2020
})
2121

22+
it('gives an error when there is no semicolon between lines', () => {
23+
const input = '@value red blue\n@value green yellow'
24+
let processor = postcss([constants])
25+
const result = processor.process(input)
26+
const warnings = result.warnings()
27+
28+
assert.equal(warnings.length, 1)
29+
assert.equal(warnings[0].text, 'Invalid value definition: red blue\n@value green yellow')
30+
})
31+
2232
it('should export a more complex constant', () => {
2333
test('@value small (max-width: 599px);', ':export {\n small: (max-width: 599px)\n}')
2434
})

0 commit comments

Comments
 (0)