Skip to content

Conversation

@elchininet
Copy link
Contributor

In one of our projects, we wanted to remove all the rules prefixed by a specific string, but at the same time, we wanted to maintain this prefix in a group of rules for internal reasons. It was impossible to do this through regular expressions due to the extension and the similarity of the rules that we wanted to remove and keep.

It would be easier to ignore the rules contained in a certain block and remove all the rules that match the criteria outside it. This pull request implements this through control directives that should be placed in comments:

Ignoring a single rule

options

{ rulesToRemove: ['.hello .h1'] }

input

a {
    font-size: 12px;
}

/* byebye:ignore */
.hello .h1 {
    background: red;
}

.hello .h1 {
    text-align: left;
}

output

a {
    font-size: 12px;
}

.hello .h1 {
    background: red;
}

Ignoring a block of rules

options

{ rulesToRemove: ['.hello .h1', '.world'] }

input

a {
    font-size: 12px;
}

/* byebye:begin:ignore */
.hello .h1 {
    background: red;
}

.world {
    color: blue;
}
/* byebye:end:ignore */

.hello .h1 {
    text-align: left;
}

.world {
    border: 1px solid #CCC;
}

output

a {
    font-size: 12px;
}

.hello .h1 {
    background: red;
}

.world {
    color: blue;
}

@AoDev
Copy link
Owner

AoDev commented Nov 16, 2021

That looks pretty cool! thanks. I'll look at your changes in the next days. (busy at work)

@elchininet elchininet force-pushed the implement_control_directives branch from d2e0c08 to 6b3065f Compare November 16, 2021 15:30
@elchininet elchininet force-pushed the implement_control_directives branch from 6b3065f to 2ab09b5 Compare November 16, 2021 15:53
@AoDev
Copy link
Owner

AoDev commented Nov 16, 2021

I realise that I need to migrate the travis CI to get the tests running again. Pushing a small update on the readme to get builds running.

@AoDev
Copy link
Owner

AoDev commented Nov 16, 2021

Alright, I see that current eslint version was not working for node 6 and 8 already. Do you mind if I drop support for these? (I saw you provided polyfills) @elchininet

@elchininet
Copy link
Contributor Author

elchininet commented Nov 16, 2021

Hi @AoDev, I‘ll fix the Eslint errors. I added the polyfills because when I tested the code in Node 6 (we have some old projects using this environment) Object.values and Array.prototype.includes were throwing errors.

@elchininet
Copy link
Contributor Author

Hi @AoDev, the Eslint errors have been fixed in the last commit.

@elchininet
Copy link
Contributor Author

Ah, I get your comment now. The current Eslint is failing under old node environments. Well, you can drop support if you want. Maybe it would be good to have the code written in ESNext and compile the package to ES5, but this can be done in a separate pull request.

@AoDev
Copy link
Owner

AoDev commented Nov 16, 2021

@elchininet Ok, since the problem is actually eslint but cssbyebye itself is fine with old node versions that you still use, I'll publish as a minor update on semver. (no breaking change release)

I'll see what to do with eslint later. If I downgrade it or just don't pay attention at failing lint for node 6 and 8.

If you setup prettier you can format the files with it, so you won't have lint issues next time.

@elchininet
Copy link
Contributor Author

Thanks, @AoDev, just let me know if you need something else from my side.
Regards

@AoDev AoDev merged commit 0394fb1 into AoDev:master Nov 17, 2021
@AoDev
Copy link
Owner

AoDev commented Nov 17, 2021

@elchininet I've published the new version to npm. (v3.1.0)
Thank you for contributing : )

@elchininet
Copy link
Contributor Author

@AoDev, that‘s great. I‘ll test it very soon.
I‘ll contribute more to the project when I have some time.
Thanks for a very simple and useful plugin 👍

@elchininet elchininet deleted the implement_control_directives branch November 17, 2021 14:50
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.

2 participants