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

added checking color #1

Merged
merged 17 commits into from
Apr 9, 2018
Merged

added checking color #1

merged 17 commits into from
Apr 9, 2018

Conversation

ablackoff
Copy link
Contributor

No description provided.

index.js Outdated
break;
}

return cssTree.fromPlainObject(cssTree.clone(ast));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s not clear if this return statement works here. I may guess, your modifications are done in ast directly.

index.js Outdated
switch (node.name) {
case 'rgb':
if(colorGenerate === initialColor.rgb.toString()) {
ast.children.map((item, index) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have many similar block, which can be extracted into one function. For example,

  1. You can provide finalColor.rgb, finalColor.rgba… as a parameter.
  2. You can set the number components to process (3 for rgb, 4 for rgba…)

I suggest replace .map() with .forEach() here. You don’t interested in a result, right? You just want to iterate over array, so .map() is irrelevant here.

index.js Outdated

switch (node.name) {
case 'rgb':
if(colorGenerate === initialColor.rgb.toString()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, format all your sources properly.

index.js Outdated

const ast = cssTree.toPlainObject(node);

const colorGenerate = ast.children.reduce((acc, item) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It‘s not clear what does this mean. colorGenerate doesn’t make sense. Why are you join these parts again?

Aside… I may guess, you are using cssTree.toPlainObject to access array methods like .map() and .reduce(). Can you confirm that there are no such methods on original object, please?

@ablackoff
Copy link
Contributor Author

made edits

Copy link
Owner

@mistakster mistakster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a little bit more issues.

test('should alter hsv colors', () => {
return postcss()
.use(alterColorPlugin({from: 'black', to: 'red'}))
.process(`div{color:hsv(0,0,0)}`, {from: undefined})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no hsv() function in CSS. Please, refer https://developer.mozilla.org/ru/docs/Web/CSS/color_value

test('should alter hsva colors', () => {
return postcss()
.use(alterColorPlugin({from: 'black', to: 'red'}))
.process(`div{color:hsva(0,0,0,1)}`, {from: undefined})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no hsva() function in CSS. Please, refer https://developer.mozilla.org/ru/docs/Web/CSS/color_value

test('should alter hsl colors', () => {
return postcss()
.use(alterColorPlugin({from: 'black', to: 'red'}))
.process(`div{color:hsl(0,0,0)}`, {from: undefined})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hsl(0,0%,0%) — don't mix integers and percentages

test('should alter hsl color in a complex value', () => {
return postcss()
.use(alterColorPlugin({from: 'black', to: 'red'}))
.process(`div{color:hsl(0,0,0);border:1px solid hsl(255,255,255);outline:1px solid hsl(0,0,0)}`, {from: undefined})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You test against invalid colours. It should be like this:

div{color:hsl(0,0%,0%);border:1px solid hsl(255,100%,100%);outline:1px solid hsl(0,0%,0%)}

test('should alter hsla colors', () => {
return postcss()
.use(alterColorPlugin({from: 'black', to: 'red'}))
.process(`div{color:hsla(0,0,0,1)}`, {from: undefined})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hsl(0,0%,0%,1) — don't mix integers and percentages

index.js Outdated
case 'hsla':
changingColorFunction(ast, checkedColor, initialColor.hsla, finalColor.hsla);
break;
case 'hsv':
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove all irrelevant switch cases.

index.js Outdated
return `${hexValue[0]}${hexValue[2]}${hexValue[4]}`;
}

function changingColorFunction(color, checkedColor, initialColor, finalColor) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your function is not working properly with "Number" and "Percentage" values.

index.js Outdated
visit: 'Function',
enter(node) {

const ast = cssTree.toPlainObject(node);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this conversion because node.children has .forEach() and .map() methods. Please, see https://github.com/csstree/csstree/blob/master/lib/utils/list.js

index.js Outdated

const ast = cssTree.toPlainObject(node);

const checkedColor = ast.children.reduce((color, item) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you get rid of such unclear conversions and compare objects by their content directly, please?

index.js Outdated
}

function changingColorFunction(color, checkedColor, initialColor, finalColor) {
if (checkedColor === initialColor.toString()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, don’t use .toString() to compare objects or arrays!

@mistakster mistakster merged commit c66c1e2 into mistakster:master Apr 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants