Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix false negatives for css-in-js object notation in color-hex-case #5101

Merged
merged 6 commits into from Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
320 changes: 320 additions & 0 deletions lib/rules/color-hex-case/__tests__/index.js
Expand Up @@ -164,3 +164,323 @@ testRule(
],
}),
);

testRule({
Dru89 marked this conversation as resolved.
Show resolved Hide resolved
ruleName,
config: ['lower'],
syntax: 'css-in-js',
fix: true,
accept: [
{
code: `
Dru89 marked this conversation as resolved.
Show resolved Hide resolved
import styled from 'styled-components';
Dru89 marked this conversation as resolved.
Show resolved Hide resolved
export const s = styled.a({
stroke: "url(#gradiantA)",
Dru89 marked this conversation as resolved.
Show resolved Hide resolved
});
`,
description: 'href with location',
},
{
code: `
import styled from 'styled-components';
export const s = styled.a({
color: "pink",
Dru89 marked this conversation as resolved.
Show resolved Hide resolved
});
`,
},
{
code: `
import styled from 'styled-components';
export const s = styled.a({
color: "#000",
Dru89 marked this conversation as resolved.
Show resolved Hide resolved
});
`,
},
{
code: `
Dru89 marked this conversation as resolved.
Show resolved Hide resolved
import styled from 'styled-components';
export const s = styled.a({
something: "#000, #fff, #ababab",
});
`,
},
{
code: `
import styled from 'styled-components';
export const s = styled.a({
color: "#0000ffcc",
});
`,
description: 'eight digits',
},
{
code: `
import styled from 'styled-components';
export const s = styled.a({
color: "#00fc",
});
`,
description: 'four digits',
},
{
code: `
Dru89 marked this conversation as resolved.
Show resolved Hide resolved
import styled from 'styled-components';
export const s = styled.a({
padding: "000",
});
`,
},
{
code: `
import styled from 'styled-components';
export const s = styled("a::before")({
content: '"#ABABA"',
Dru89 marked this conversation as resolved.
Show resolved Hide resolved
});
`,
},
{
code: `
import styled from 'styled-components';
export const s = styled.a({
color: "white /* #FFF */",
});
`,
},
],

reject: [
{
code: `
import styled from 'styled-components';
export const s = styled.a({
color: "#aBABA",
Dru89 marked this conversation as resolved.
Show resolved Hide resolved
});
`,
fixed: `
import styled from 'styled-components';
export const s = styled.a({
color: "#ababa",
Dru89 marked this conversation as resolved.
Show resolved Hide resolved
});
`,

message: messages.expected('#aBABA', '#ababa'),
Dru89 marked this conversation as resolved.
Show resolved Hide resolved
line: 4,
column: 9,
},
{
code: `
Dru89 marked this conversation as resolved.
Show resolved Hide resolved
import styled from 'styled-components';
export const s = styled.a({
something: "#000F, #fff, #abababA",
});
`,
fixed: `
import styled from 'styled-components';
export const s = styled.a({
something: "#000f, #fff, #abababa",
});
`,

warnings: [
{ message: messages.expected('#000F', '#000f'), line: 4, column: 13 },
{ message: messages.expected('#abababA', '#abababa'), line: 4, column: 26 },
],
},
{
code: `
import styled from 'styled-components';
export const s = styled.a({
something: "#000, #FFFFAZ, #ababab",
});
`,
fixed: `
import styled from 'styled-components';
export const s = styled.a({
something: "#000, #ffffaz, #ababab",
});
`,

message: messages.expected('#FFFFAZ', '#ffffaz'),
line: 4,
column: 19,
},
{
code: `
import styled from 'styled-components';
export const s = styled.a({
something: "#000, #fff, #12345AA",
});
`,
fixed: `
import styled from 'styled-components';
export const s = styled.a({
something: "#000, #fff, #12345aa",
});
`,

message: messages.expected('#12345AA', '#12345aa'),
line: 4,
column: 25,
},
],
});

testRule({
Dru89 marked this conversation as resolved.
Show resolved Hide resolved
ruleName,
config: ['upper'],
syntax: 'css-in-js',
fix: true,
accept: [
{
code: `
import styled from 'styled-components';
export const s = styled.a({
stroke: "url(#gradiantA)",
});
`,
description: 'href with location',
},
{
code: `
import styled from 'styled-components';
export const s = styled.a({
color: "pink",
});
`,
},
{
code: `
import styled from 'styled-components';
export const s = styled.a({
color: "#000",
});
`,
},
{
code: `
import styled from 'styled-components';
export const s = styled.a({
something: "#000, #FFF, #ABABAB",
});
`,
},
{
code: `
import styled from 'styled-components';
export const s = styled.a({
color: "#0000FFCC",
});
`,
description: 'eight digits',
},
{
code: `
import styled from 'styled-components';
export const s = styled.a({
color: "#00FC",
});
`,
description: 'four digits',
},
{
code: `
import styled from 'styled-components';
export const s = styled.a({
padding: "000",
});
`,
},
{
code: `
import styled from 'styled-components';
export const s = styled("a::before")({
content: '"#ababa"',
});
`,
},
{
code: `
import styled from 'styled-components';
export const s = styled.a({
color: "white /* #fff */",
});
`,
},
],

reject: [
{
code: `
import styled from 'styled-components';
export const s = styled.a({
color: "#aBABA",
});
`,
fixed: `
import styled from 'styled-components';
export const s = styled.a({
color: "#ABABA",
});
`,

message: messages.expected('#aBABA', '#ABABA'),
line: 4,
column: 9,
},
{
code: `
import styled from 'styled-components';
export const s = styled.a({
something: "#000f, #FFF, #abababA",
});
`,
fixed: `
import styled from 'styled-components';
export const s = styled.a({
something: "#000F, #FFF, #ABABABA",
});
`,

warnings: [
{ message: messages.expected('#000f', '#000F'), line: 4, column: 13 },
{ message: messages.expected('#abababA', '#ABABABA'), line: 4, column: 26 },
],
},
{
code: `
import styled from 'styled-components';
export const s = styled.a({
something: "#000, #ffffaz, #ABABAB",
});
`,
fixed: `
import styled from 'styled-components';
export const s = styled.a({
something: "#000, #FFFFAZ, #ABABAB",
});
`,

message: messages.expected('#ffffaz', '#FFFFAZ'),
line: 4,
column: 19,
},
{
code: `
import styled from 'styled-components';
export const s = styled.a({
something: "#000, #FFF, #12345aa",
});
`,
fixed: `
import styled from 'styled-components';
export const s = styled.a({
something: "#000, #FFF, #12345AA",
});
`,

message: messages.expected('#12345aa', '#12345AA'),
line: 4,
column: 25,
},
],
});