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 annotation-no-unknown #6155

Merged
merged 8 commits into from Jun 21, 2022
Merged

Add annotation-no-unknown #6155

merged 8 commits into from Jun 21, 2022

Conversation

mattxwang
Copy link
Member

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

Closes #4508.

Is there anything in the PR that needs further explanation?

A late turnaround on this one! I think there's probably a few missing things before this is mergeable.

Possible questions with my implementation:

  • how should I be checking for nonstandard syntax? ex just at the declaration level?
  • should !important be case-insensitive? on one hand, syntax highlighters and the literal reading of the spec only allow for lowercase, but it seems like Chrome respects any capitalization.
  • I've opted to include the ! in the secondary options; is that too clunky?
  • should I add any testcases for nonstandard syntax?

Possible questions with my implementation:
- how should I be checking for nonstandard syntax?
  ex just at the declaration level?
- I've interpreted the spec to allow any capitalization of important,
  but I could be wrong here! I did test on Chrome and it seems to allow
  case-insensitive responses.
- I've opted to include the `!` in the secondary options; is that too
  clunky?
- should I add any testcases for nonstandard syntax?
@mattxwang
Copy link
Member Author

Actually - going to mark this as draft; I think I've made an implementation mistake that the code coverage sneakily catches. I'll revisit and mark as ready when relevant!

@mattxwang mattxwang marked this pull request as draft June 19, 2022 06:58
@ybiquitous
Copy link
Member

@mattxwang Thanks for creating the pull request! 👍🏼

Here are my answers to your questions in the description:

  • how should I be checking for nonstandard syntax? ex just at the declaration level?
  • should I add any testcases for nonstandard syntax?

If you would have clear test cases for non-standard syntaxes, it might be nice to check them to reduce potential false positives. But if you wouldn't have them or the rule implementation would be much more complex by adding such a check, it would be acceptable not to check them.

  • should !important be case-insensitive? on one hand, syntax highlighters and the literal reading of the spec only allow for lowercase, but it seems like Chrome respects any capitalization.

It seems good that !important be case-sensitive. We have similar code already:

const pattern = /!\s*important\b/gi;

  • I've opted to include the ! in the secondary options; is that too clunky?

I think it's unnecessary for consistency to include ! because the ignoreAtRules option of property-no-unknown doesn't @.

### `ignoreAtRules: ["/regex/", /regex/, "string"]`
Ignores properties nested within specified at-rules.
Given:
```json
["supports"]
```

Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

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

@mattxwang Thanks for making a start on this. Looking good so far.

I've requested some changes to make the docs, tests and rule consistent with existing rules.

Let's not add additional tests for non-standard syntax. Only if users report an issue, should we add that code.

I agree with @ybiquitous that it's unnecessary to include !.

docs/user-guide/rules/list.md Outdated Show resolved Hide resolved
lib/rules/annotation-no-unknown/README.md Outdated Show resolved Hide resolved
lib/rules/annotation-no-unknown/README.md Outdated Show resolved Hide resolved
lib/rules/annotation-no-unknown/index.js Show resolved Hide resolved
lib/rules/annotation-no-unknown/README.md Outdated Show resolved Hide resolved
lib/rules/annotation-no-unknown/README.md Outdated Show resolved Hide resolved
lib/rules/annotation-no-unknown/README.md Outdated Show resolved Hide resolved
mattxwang and others added 6 commits June 20, 2022 11:42
Co-authored-by: Richard Hallows <jeddy3@users.noreply.github.com>
Co-authored-by: Richard Hallows <jeddy3@users.noreply.github.com>
Co-authored-by: Richard Hallows <jeddy3@users.noreply.github.com>
Co-authored-by: Richard Hallows <jeddy3@users.noreply.github.com>
@mattxwang
Copy link
Member Author

Thank you @ybiquitous and @jeddy3 for the in-depth feedback, I appreciate both of you and your patience as I still getting familiar with the codebase. I definitely need to do a better job of following the conventions doc!

I think I've resolved all of the outstanding changes, and I've removed the need to use ! (not sure if the way that I've done it is hacky).

One note:

It seems good that !important be case-sensitive.

With my understanding of the PostCSS parser, the top-level declaration doesn't differentiate between different capitalizations of !important. There is a different value in the raws field that I could use to check if the annotation is a lowercase !important. With that in mind, should I add a check for that in the rule (making the rule case-sensitive)? Or, should I leave it as is (case-insensitive)?

$ node -e 'require("postcss").parse("a { color: red !IMPORTANT }").walkDecls(decl => console.log(decl))'
<ref *1> Declaration {
  raws: { before: ' ', between: ': ', important: ' !IMPORTANT' },
  type: 'decl',
  parent: Rule {
    raws: { before: '', between: ' ', semicolon: false, after: ' ' },
    type: 'rule',
    nodes: [ [Circular *1] ],
    parent: Root {
      raws: [Object],
      type: 'root',
      nodes: [Array],
      source: [Object],
      lastEach: 1,
      indexes: [Object],
      [Symbol(isClean)]: false,
      [Symbol(my)]: true
    },
    source: { start: [Object], input: [Input], end: [Object] },
    selector: 'a',
    lastEach: 1,
    indexes: { '1': 0 },
    [Symbol(isClean)]: false,
    [Symbol(my)]: true
  },
  source: {
    start: { offset: 4, line: 1, column: 5 },
    input: Input {
      css: 'a { color: red !IMPORTANT }',
      hasBOM: false,
      id: '<input css HyYU1z>',
      [Symbol(fromOffsetCache)]: [Array]
    },
    end: { offset: 24, line: 1, column: 25 }
  },
  prop: 'color',
  important: true,
  value: 'red',
  [Symbol(isClean)]: false,
  [Symbol(my)]: true
}

@mattxwang mattxwang marked this pull request as ready for review June 20, 2022 19:06
@ybiquitous
Copy link
Member

With my understanding of the PostCSS parser, the top-level declaration doesn't differentiate between different capitalizations of !important.

Sorry, let's follow the current PostCSS parser behavior!

Copy link
Member

@ybiquitous ybiquitous left a comment

Choose a reason for hiding this comment

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

@mattxwang Thanks for the quick fix! I've left a suggestion comment, but this looks mostly good to me. 👍🏼

lib/rules/annotation-no-unknown/index.js Show resolved Hide resolved
Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
Copy link
Member

@ybiquitous ybiquitous left a comment

Choose a reason for hiding this comment

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

Thank you. LGTM 👍🏼

Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

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

Thanks for making the changes. LGTM, thank you!

@jeddy3 jeddy3 merged commit a3e655d into main Jun 21, 2022
@jeddy3 jeddy3 deleted the add-annotation-no-unknown branch June 21, 2022 10:02
@jeddy3
Copy link
Member

jeddy3 commented Jun 21, 2022

  • Added: annotation-no-unknown rule (#6155).

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

Successfully merging this pull request may close these issues.

Add annotation-no-unknown
3 participants