Skip to content
This repository was archived by the owner on Feb 9, 2023. It is now read-only.

Commit b4b5414

Browse files
authored
Remove hardcoded transform from float to cssFloat in objects (#172)
The value should only be transformed if the raw value was also "cssFloat". Otherwise, we should allow the user to use the "float" keyword in the cases it is actually valid, which we can't easily detect. Misuse of the keyword can be caught by Javascript code analysis tools. Fixes: stylelint/stylelint#4490
1 parent 9579653 commit b4b5414

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

object-stringifier.js

-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ class ObjectStringifier extends Stringifier {
2626
decl(node, semicolon) {
2727
let prop = this.rawValue(node, 'prop');
2828

29-
if (prop === 'float') {
30-
prop = 'cssFloat';
31-
}
32-
3329
let string = prop;
3430

3531
const isObjectShorthand = node.raws.node && node.raws.node.shorthand;

test/css-in-js.js

+16-13
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ describe('CSS in JS', () => {
128128
`);
129129
});
130130

131-
it('float', () => {
131+
it('cssFloat', () => {
132132
const code = `
133133
import glm from 'glamorous';
134134
const Component1 = glm.a({
@@ -148,21 +148,24 @@ describe('CSS in JS', () => {
148148
cssFloat: "left",
149149
});
150150
`);
151+
});
151152

152-
root.first.first.nodes = [
153-
postcss.decl({
154-
prop: 'float',
155-
value: 'right',
156-
raws: {
157-
before: root.first.first.first.raws.before,
158-
},
159-
}),
160-
];
153+
it('float', () => {
154+
const code = `
155+
const component = styled(Btn)({
156+
float: "left",
157+
});
158+
`;
159+
160+
const root = syntax.parse(code, {
161+
from: '/fixtures/styled-float.jsx',
162+
});
163+
164+
expect(root.first.first.first).toHaveProperty('prop', 'float');
161165

162166
expect(root.toString()).toBe(`
163-
import glm from 'glamorous';
164-
const Component1 = glm.a({
165-
cssFloat: "right",
167+
const component = styled(Btn)({
168+
float: "left",
166169
});
167170
`);
168171
});

0 commit comments

Comments
 (0)