8000 feat(eslint-plugin-template): [no-restricted-syntax] add rule by rafaelss95 · Pull Request #698 · angular-eslint/angular-eslint · GitHub
[go: up one dir, main page]

Skip to content

feat(eslint-plugin-template): [no-restricted-syntax] add rule #698

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

Conversation

rafaelss95
Copy link
Member
@rafaelss95 rafaelss95 commented Sep 20, 2021

Closes #655.

Note that the first two commits are from #697.


## Rule Options

The rule does not have any configuration options.
Copy link
Member Author

Choose a reason for hiding this comment

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


<br>

✅ - Examples of **correct** code for this rule:
Copy link
Member Author
@rafaelss95 rafaelss95 Sep 20, 2021

Choose a reason for hiding this comment

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

Hmmm .. the generator only grab tests that don't contain options, right? What can we do for this case here since the rule has no defaults + the options are not optional?

Just noticed that we have the same problems for component-selector and directive-selector.

Copy link
Member

Choose a reason for hiding this comment

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

Working on it now


<br>

❌ - Examples of **incorrect** code for this rule:
Copy link
Member Author

Choose a reason for hiding this comment

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

For these examples, it would be great to have the options defined somewhere (perhaps in the form of a comment).

Copy link
Member

Choose a reason for hiding this comment

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

Working on it now

import type { AbsoluteSourceSpan } from '@angular/compiler';
import type { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils';

export function getLocFromAbsoluteSourceSpan(
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if it's the best name + the best place, but I do think it's a good ideia to have this utility (we can refactor the rules to use it in another PR).

@rafaelss95 rafaelss95 force-pushed the feat/template/no-restricted-syntax branch from ba40b99 to 00bcb30 Compare September 20, 2021 22:50
Comment on lines +77 to +78
// If the `selector` is already computed (it can happens in case of passing `string` + object format), we just ignore it.
...(!(selector in selectors) && { [selector]: visitor(message) }),
Copy link
Member Author
@rafaelss95 rafaelss95 Sep 20, 2021

Choose a reason for hiding this comment

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

To be clear, it's preventing the following case:

{
  "@angular-eslint/template/no-restricted-syntax": [
    "error",
    "BoundAttribute",
    {
      "selector": "BoundAttribute" // note that it's duplicated.
    },
  ]  
}

AFAIK, we can't prevent this using schema.


That being said:

  1. Not sure if this comment is clear enough, let me know in case of rephrase needed.
  2. Or perhaps would it be better to give a warning?

Copy link
Member

Choose a reason for hiding this comment

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

This seems to be the opposite behavior to the existing core rule for JS: https://github.com/eslint/eslint/blob/d36f12f71b3e4f9e9552f1054d7a75be4dc03671/lib/rules/no-restricted-syntax.js#L58

The latest definition for that selector will replace previous ones via the Object.assign.

I think it would be better to match the existing rule here, regardless of whether we agree with it or not

@rafaelss95 rafaelss95 force-pushed the feat/template/no-restricted-syntax branch 2 times, most recently from 467efc8 to d8b7a59 Compare September 20, 2021 23:09
@JamesHenry
Copy link
Member

Sorry, this one will need to be updated as I don't think it's best to move ahead with the TS 4.4 one yet

@JamesHenry
Copy link
Member

Config/options in docs is now supported as of: #699

@rafaelss95 rafaelss95 force-pushed the feat/template/no-restricted-syntax branch from d8b7a59 to 3e9ac6c Compare September 22, 2021 15:11
@codecov
Copy link
codecov bot commented Sep 22, 2021

Codecov Report

Merging #698 (c74013d) into master (8ac2193) will increase coverage by 0.17%.
The diff coverage is 100.00%.

❗ Current head c74013d differs from pull request most recent head 319c778. Consider uploading reports for the commit 319c778 to get more accurate results

@@            Coverage Diff             @@
##           master     #698      +/-   ##
==========================================
+ Coverage   85.37%   85.55%   +0.17%     
==========================================
  Files          83       85       +2     
  Lines        1922     1945      +23     
  Branches      339      343       +4     
==========================================
+ Hits         1641     1664      +23     
  Misses        170      170              
  Partials      111      111              
Impacted Files Coverage Δ
...-plugin-template/src/rules/no-restricted-syntax.ts 100.00% <100.00%> (ø)
...ate/src/utils/get-loc-from-absolute-source-span.ts 100.00% <100.00%> (ø)

@miluoshi
Copy link

Hi, is this waiting for this to be fixed?

Copy link
Member
@JamesHenry JamesHenry left a comment

Choose a reason for hiding this comment

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

This is excellent, thanks so much @rafaelss95! Just the one point to deal with around multiple selector definitions.

I'm really sorry it took me so long to get this reviewed, but thank you again for all your hard work 🙏

@JamesHenry
Copy link
Member

I emailed Rafael about 2 months ago asking if wished to continue working on this but sadly have not received a response in that time. I will therefore close this so that it is clear that it is not being worked on and that somebody else can pick this up if it is important to them.

Many thanks to Rafael for his fantastic contributions to angular-eslint to date 🙏

@JamesHenry JamesHenry closed this Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule proposal: template/no-restricted-syntax
3 participants
0