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

Commit 3167e86

Browse files
feat: add support for validation in substitution
1 parent 7dbacd3 commit 3167e86

File tree

5 files changed

+128
-2
lines changed

5 files changed

+128
-2
lines changed

src/utils/result.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ exports.isCausedBySubstitution = (warning, line, interpolationLines) =>
22
interpolationLines.some(({ start, end }) => {
33
if (line > start && line < end) {
44
// Inner interpolation lines must be
5-
return true
5+
return (
6+
['value-list-max-empty-lines', 'comment-empty-line-before', 'indentation'].indexOf(
7+
warning.rule
8+
) >= 0
9+
)
610
} else if (line === start) {
711
return ['value-list-max-empty-lines', 'comment-empty-line-before'].indexOf(warning.rule) >= 0
812
} else if (line === end) {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import styled, { css } from 'styled-components';
2+
import React from 'react'
3+
4+
export default props => {
5+
const CirclePrimitive = styled.div`
6+
// next line has wrong property
7+
widthh: 100%;
8+
height: 100%;
9+
position: absolute;
10+
left: 0;
11+
top: 0;
12+
${props.rotate && css`
13+
-webkit-transform: rotate(${props.rotate}deg);
14+
-ms-transform: rotate(${props.rotate}deg);
15+
transform: rotate(${props.rotate}deg);
16+
`}
17+
18+
&:before {
19+
content: '';
20+
display: block;
21+
margin: 0 auto;
22+
width: 15%;
23+
height: 15%;
24+
// next line has wrong property
25+
background-colorr: #333;
26+
border-radius: 100%;
27+
animation: ${animations.spinnerCircle} 1.2s infinite ease-in-out both;
28+
${props.delay && css`
29+
-webkit-animation-delay: ${props.delay}s;
30+
animation-delay: ${props.delay}s;
31+
`}
32+
}
33+
`
34+
return React.createElement(CirclePrimitive)
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import styled, { css } from 'styled-components';
2+
import React from 'react'
3+
4+
export default props => {
5+
const CirclePrimitive = styled.div`
6+
width: 100%;
7+
height: 100%;
8+
position: absolute;
9+
left: 0;
10+
top: 0;
11+
${props.rotate && css`
12+
-webkit-transform: rotate(${props.rotate}deg);
13+
-ms-transform: rotate(${props.rotate}deg);
14+
// next line has wrong property
15+
transformm: rotate(${props.rotate}deg);
16+
`}
17+
18+
&:before {
19+
content: '';
20+
display: block;
21+
margin: 0 auto;
22+
width: 15%;
23+
height: 15%;
24+
background-color: #333;
25+
border-radius: 100%;
26+
animation: ${animations.spinnerCircle} 1.2s infinite ease-in-out both;
27+
${props.delay && css`
28+
-webkit-animation-delay: ${props.delay}s;
29+
// next line has wrong property
30+
animation-delayy: ${props.delay}s;
31+
`}
32+
}
33+
`
34+
return React.createElement(CirclePrimitive)
35+
}

test/hard.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,54 @@ describe('hard', () => {
166166
})
167167
})
168168
})
169+
170+
describe('invalid properties', () => {
171+
describe('valid', () => {
172+
beforeAll(() => {
173+
fixture = slash(path.join(__dirname, './fixtures/hard/invalid-properties.js'))
174+
})
175+
176+
it('should have one result', () => {
177+
expect(data.results.length).toEqual(1)
178+
})
179+
180+
it('should use the right file', () => {
181+
expect(slash(data.results[0].source)).toEqual(fixture)
182+
})
183+
184+
it('should have errored', () => {
185+
expect(data.errored).toEqual(true)
186+
})
187+
188+
it('should not have any warnings', () => {
189+
console.log(data)
190+
expect(data.results[0].warnings.length).toEqual(2)
191+
})
192+
})
193+
})
194+
195+
describe('invalid substitution properties', () => {
196+
describe('valid', () => {
197+
beforeAll(() => {
198+
fixture = slash(path.join(__dirname, './fixtures/hard/invalid-substitution-properties.js'))
199+
})
200+
201+
it('should have one result', () => {
202+
expect(data.results.length).toEqual(1)
203+
})
204+
205+
it('should use the right file', () => {
206+
expect(slash(data.results[0].source)).toEqual(fixture)
207+
})
208+
209+
it('should have errored', () => {
210+
expect(data.errored).toEqual(true)
211+
})
212+
213+
it('should not have any warnings', () => {
214+
console.log(data)
215+
expect(data.results[0].warnings.length).toEqual(2)
216+
})
217+
})
218+
})
169219
})

test/utils.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,9 @@ html {
632632
{ start: 5, end: 5 }
633633
]
634634
it("returns true if real warning line is between some interpolation's start and end", () => {
635-
expect(fn({ rule: 'any rule' }, 3, interpolationLines)).toEqual(true)
635+
expect(fn({ rule: 'value-list-max-empty-lines' }, 3, interpolationLines)).toEqual(true)
636+
expect(fn({ rule: 'comment-empty-line-before' }, 3, interpolationLines)).toEqual(true)
637+
expect(fn({ rule: 'indentation' }, 3, interpolationLines)).toEqual(true)
636638
})
637639
it("returns false if real warning line is beyond any interpolation's start and end", () => {
638640
expect(fn({ rule: 'any rule' }, 1, interpolationLines)).toEqual(false)

0 commit comments

Comments
 (0)