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

Add autofix to selector-attribute-quotes #5248

Conversation

@doing-art
Copy link
Contributor

@doing-art doing-art commented Apr 15, 2021

Which issue, if any, is this issue related to?

Have added autofix to selector-attribute-quotes rule as dicussed in issue #5211

Is there anything in the PR that needs further explanation?

Some of the unit tests can be a bit confusing. They cover pretty unusual but valid selectors:

[href=te\'s\"t] { }
[href=\"test\"] { }
[href=\'test\'] { }
[href="te'st"] { }
[href='te"st'] { }
[href='te\'st'] { }
[href="te\"st"] { }
@jeddy3 jeddy3 changed the title Add autofix to selector attribute quotes Add autofix to selector-attribute-quotes Apr 20, 2021
Copy link
Member

@jeddy3 jeddy3 left a comment

@doing-art Thank you for the pull request. It's almost there.

Can we add a test with a comment within a selector list please, e.g.:

{
  code: 'a[target="_blank"], /* comment */ a { }',
  fixed: 'a[target=_blank], /* comment */ a { }',
  message: messages.rejected('_blank'),
  line: 1,
  column: 10,
},

It'll fail because comments are stripped for the selector property of the AST. The full string is available in the raws property, and we'll want to pass this full string to the selector parser. (Ref).

Let's create a getRuleSelector util based off getDeclarationValue and use it in the rule.

Loading

@@ -36,25 +38,41 @@ function rule(expectation) {
}

parseSelector(ruleNode.selector, result, ruleNode, (selectorTree) => {
Copy link
Member

@jeddy3 jeddy3 Apr 20, 2021

Choose a reason for hiding this comment

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

Suggested change
parseSelector(ruleNode.selector, result, ruleNode, (selectorTree) => {
parseSelector(getRuleSelector(ruleNode), result, ruleNode, (selectorTree) => {

We'll need a new util here.

Loading

Copy link
Contributor Author

@doing-art doing-art Apr 21, 2021

Choose a reason for hiding this comment

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

@doing-art Thank you for the pull request. It's almost there.

Can we add a test with a comment within a selector list please, e.g.:

{
  code: 'a[target="_blank"], /* comment */ a { }',
  fixed: 'a[target=_blank], /* comment */ a { }',
  message: messages.rejected('_blank'),
  line: 1,
  column: 10,
},

It'll fail because comments are stripped for the selector property of the AST. The full string is available in the raws property, and we'll want to pass this full string to the selector parser. (Ref).

Let's create a getRuleSelector util based off getDeclarationValue and use it in the rule.

@jeddy3 Thanks for reviewing the PR. I made the requested change.

Loading

@jeddy3 jeddy3 mentioned this pull request Apr 21, 2021
6 tasks
@doing-art doing-art requested a review from jeddy3 Apr 21, 2021
jeddy3
jeddy3 approved these changes Apr 21, 2021
Copy link
Member

@jeddy3 jeddy3 left a comment

Thanks for making the changes.

LGTM.

Loading

Copy link
Member

@mattxwang mattxwang left a comment

LGTM, seems like a comprehensive set of test cases to me!

Loading

@jeddy3 jeddy3 merged commit 2a35e1a into stylelint:master Apr 23, 2021
13 checks passed
Loading
@jeddy3
Copy link
Member

@jeddy3 jeddy3 commented Apr 23, 2021

Changelog entry added:

  • Added: selector-attribute-quotes autofix (#5248).

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants