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

feat(eslint-plugin-template): export template parser services #1211

Merged

Conversation

reduckted
Copy link
Contributor

@reduckted reduckted commented Nov 19, 2022

Fixes #888

This exports the TemplateParserServices type (previously called ParserServices in the eslint-plugin-template package), and the getTemplateParserServices and ensureTemplateParser functions.

You should now be able to create a template-based rule like this:

import type { TemplateParserServices } from '@angular-eslint/utils';
import { getTemplateParserServices } from '@angular-eslint/utils';
import type { TmplAstBoundAttribute } from '@angular/compiler';
import { ESLintUtils } from '@typescript-eslint/utils';

const rule = ESLintUtils.RuleCreator.withoutDocs({
  meta: {
    type: 'problem',
    messages: { foo: 'bar' },
    schema: {},
  },
  defaultOptions: [],
  create: (context) => {
    const parser: TemplateParserServices = getTemplateParserServices(context);

    return {
      BoundProperty: (node: TmplAstBoundAttribute) => {
        context.report({
          messageId: 'foo',
          loc: parser.convertNodeSourceSpanToLoc(node.sourceSpan),
        });
      },
    };
  },
});

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.

Thanks a lot @reduckted!

Please regorganize things so that anything which is exported to end users comes from the utils package, as that is more of a natural fit.

Until now the convention has been that anything within the utils folder within a plugin is private to that plugin, anything within @angular-eslint/utils could potentially be exported

@reduckted
Copy link
Contributor Author

No problem. That makes perfect sense. 👍

@JamesHenry
Copy link
Member

@reduckted Do you think you can update it today? If so we can merge it and release it as a final v14, otherwise I'm afraid it will be in the first minor of v15

@reduckted reduckted force-pushed the feature/export-template-rule-creator branch from 47a0fb3 to b472b84 Compare November 20, 2022 11:02
@reduckted
Copy link
Contributor Author

reduckted commented Nov 20, 2022

Yes, I've actually just pushed up the changes (hopefully everything is in the correct place now).

I've reverted the change to export the createESLintRule function, because I don't believe that function needed to be exported to create template rules (the @angular-eslint/eslint-plugin has a similar function that is private).

@reduckted reduckted changed the title feat(eslint-plugin-template): export template parser services and rule creator feat(eslint-plugin-template): export template parser services Nov 20, 2022
@JamesHenry
Copy link
Member

@reduckted please update your example to match the new expectations (for posterity)

@JamesHenry
Copy link
Member

@reduckted just FYI I decided to go for TemplateParserServices for maximum clarity (I also updated it in your example).

Many thanks again!

@codecov
Copy link

codecov bot commented Nov 20, 2022

Codecov Report

Merging #1211 (f147361) into main (0273649) will increase coverage by 0.16%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1211      +/-   ##
==========================================
+ Coverage   88.16%   88.33%   +0.16%     
==========================================
  Files         161      161              
  Lines        3093     3112      +19     
  Branches      500      498       -2     
==========================================
+ Hits         2727     2749      +22     
+ Misses        253      252       -1     
+ Partials      113      111       -2     
Flag Coverage Δ
unittest 88.33% <100.00%> (+0.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...lint-plugin-template/src/rules/attributes-order.ts 100.00% <ø> (ø)
...lugin-template/src/rules/conditional-complexity.ts 100.00% <ø> (ø)
packages/eslint-plugin-template/src/rules/i18n.ts 94.00% <ø> (+0.06%) ⬆️
...nt-plugin-template/src/utils/create-eslint-rule.ts 100.00% <ø> (+17.64%) ⬆️
...lugin-template/src/rules/accessibility-alt-text.ts 92.30% <100.00%> (+0.15%) ⬆️
...mplate/src/rules/accessibility-elements-content.ts 95.65% <100.00%> (+0.19%) ⬆️
.../rules/accessibility-interactive-supports-focus.ts 92.00% <100.00%> (+0.33%) ⬆️
...ugin-template/src/rules/accessibility-label-for.ts 88.88% <100.00%> (+0.42%) ⬆️
...ules/accessibility-label-has-associated-control.ts 82.75% <100.00%> (+0.61%) ⬆️
.../src/rules/accessibility-role-has-required-aria.ts 90.00% <100.00%> (+0.34%) ⬆️
... and 44 more

@JamesHenry JamesHenry merged commit 34a62d2 into angular-eslint:main Nov 20, 2022
@reduckted reduckted deleted the feature/export-template-rule-creator branch November 20, 2022 12:25
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Nov 28, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@angular-eslint/builder](https://github.com/angular-eslint/angular-eslint) | devDependencies | minor | [`14.2.0` -> `14.4.0`](https://renovatebot.com/diffs/npm/@angular-eslint%2fbuilder/14.2.0/14.4.0) |
| [@angular-eslint/eslint-plugin](https://github.com/angular-eslint/angular-eslint) | devDependencies | minor | [`14.2.0` -> `14.4.0`](https://renovatebot.com/diffs/npm/@angular-eslint%2feslint-plugin/14.2.0/14.4.0) |
| [@angular-eslint/eslint-plugin-template](https://github.com/angular-eslint/angular-eslint) | devDependencies | minor | [`14.2.0` -> `14.4.0`](https://renovatebot.com/diffs/npm/@angular-eslint%2feslint-plugin-template/14.2.0/14.4.0) |
| [@angular-eslint/schematics](https://github.com/angular-eslint/angular-eslint) | devDependencies | minor | [`14.2.0` -> `14.4.0`](https://renovatebot.com/diffs/npm/@angular-eslint%2fschematics/14.2.0/14.4.0) |
| [@angular-eslint/template-parser](https://github.com/angular-eslint/angular-eslint) | devDependencies | minor | [`14.2.0` -> `14.4.0`](https://renovatebot.com/diffs/npm/@angular-eslint%2ftemplate-parser/14.2.0/14.4.0) |

---

### Release Notes

<details>
<summary>angular-eslint/angular-eslint (@&#8203;angular-eslint/builder)</summary>

### [`v14.4.0`](https://github.com/angular-eslint/angular-eslint/blob/HEAD/packages/builder/CHANGELOG.md#&#8203;1440-httpsgithubcomangular-eslintangular-eslintcomparev1431v1440-2022-11-20)

[Compare Source](angular-eslint/angular-eslint@v14.3.1...v14.4.0)

**Note:** Version bump only for package [@&#8203;angular-eslint/builder](https://github.com/angular-eslint/builder)

#### [14.3.1](angular-eslint/angular-eslint@v14.3.0...v14.3.1) (2022-11-20)

**Note:** Version bump only for package [@&#8203;angular-eslint/builder](https://github.com/angular-eslint/builder)

### [`v14.3.1`](https://github.com/angular-eslint/angular-eslint/blob/HEAD/packages/builder/CHANGELOG.md#&#8203;1431-httpsgithubcomangular-eslintangular-eslintcomparev1430v1431-2022-11-20)

[Compare Source](angular-eslint/angular-eslint@v14.3.0...v14.3.1)

**Note:** Version bump only for package [@&#8203;angular-eslint/builder](https://github.com/angular-eslint/builder)

### [`v14.3.0`](https://github.com/angular-eslint/angular-eslint/blob/HEAD/packages/builder/CHANGELOG.md#&#8203;1430-httpsgithubcomangular-eslintangular-eslintcomparev1420v1430-2022-11-17)

[Compare Source](angular-eslint/angular-eslint@v14.2.0...v14.3.0)

**Note:** Version bump only for package [@&#8203;angular-eslint/builder](https://github.com/angular-eslint/builder)

</details>

<details>
<summary>angular-eslint/angular-eslint (@&#8203;angular-eslint/eslint-plugin)</summary>

### [`v14.4.0`](https://github.com/angular-eslint/angular-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#&#8203;1440-httpsgithubcomangular-eslintangular-eslintcomparev1431v1440-2022-11-20)

[Compare Source](angular-eslint/angular-eslint@v14.3.1...v14.4.0)

**Note:** Version bump only for package [@&#8203;angular-eslint/eslint-plugin](https://github.com/angular-eslint/eslint-plugin)

#### [14.3.1](angular-eslint/angular-eslint@v14.3.0...v14.3.1) (2022-11-20)

##### Bug Fixes

-   **no-input-rename:** allow input aliases that match the directive name applied to an element ([#&#8203;1207](angular-eslint/angular-eslint#1207)) ([aff3344](angular-eslint/angular-eslint@aff3344))

### [`v14.3.1`](https://github.com/angular-eslint/angular-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#&#8203;1431-httpsgithubcomangular-eslintangular-eslintcomparev1430v1431-2022-11-20)

[Compare Source](angular-eslint/angular-eslint@v14.3.0...v14.3.1)

##### Bug Fixes

-   **no-input-rename:** allow input aliases that match the directive name applied to an element ([#&#8203;1207](angular-eslint/angular-eslint#1207)) ([aff3344](angular-eslint/angular-eslint@aff3344))

### [`v14.3.0`](https://github.com/angular-eslint/angular-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#&#8203;1430-httpsgithubcomangular-eslintangular-eslintcomparev1420v1430-2022-11-17)

[Compare Source](angular-eslint/angular-eslint@v14.2.0...v14.3.0)

**Note:** Version bump only for package [@&#8203;angular-eslint/eslint-plugin](https://github.com/angular-eslint/eslint-plugin)

</details>

<details>
<summary>angular-eslint/angular-eslint (@&#8203;angular-eslint/eslint-plugin-template)</summary>

### [`v14.4.0`](https://github.com/angular-eslint/angular-eslint/blob/HEAD/packages/eslint-plugin-template/CHANGELOG.md#&#8203;1440-httpsgithubcomangular-eslintangular-eslintcomparev1431v1440-2022-11-20)

[Compare Source](angular-eslint/angular-eslint@v14.3.1...v14.4.0)

##### Features

-   **utils:** export template parser services ([#&#8203;1211](angular-eslint/angular-eslint#1211)) ([34a62d2](angular-eslint/angular-eslint@34a62d2))

#### [14.3.1](angular-eslint/angular-eslint@v14.3.0...v14.3.1) (2022-11-20)

**Note:** Version bump only for package [@&#8203;angular-eslint/eslint-plugin-template](https://github.com/angular-eslint/eslint-plugin-template)

### [`v14.3.1`](https://github.com/angular-eslint/angular-eslint/blob/HEAD/packages/eslint-plugin-template/CHANGELOG.md#&#8203;1431-httpsgithubcomangular-eslintangular-eslintcomparev1430v1431-2022-11-20)

[Compare Source](angular-eslint/angular-eslint@v14.3.0...v14.3.1)

**Note:** Version bump only for package [@&#8203;angular-eslint/eslint-plugin-template](https://github.com/angular-eslint/eslint-plugin-template)

### [`v14.3.0`](https://github.com/angular-eslint/angular-eslint/blob/HEAD/packages/eslint-plugin-template/CHANGELOG.md#&#8203;1430-httpsgithubcomangular-eslintangular-eslintcomparev1420v1430-2022-11-17)

[Compare Source](angular-eslint/angular-eslint@v14.2.0...v14.3.0)

##### Features

-   **eslint-plugin-template:** \[accessibility-elements-content] add allowList option ([#&#8203;1201](angular-eslint/angular-eslint#1201)) ([3877f43](angular-eslint/angular-eslint@3877f43))
-   **eslint-plugin-template:** \[no-inline-styles] add rule ([#&#8203;1162](angular-eslint/angular-eslint#1162)) ([7e1aadf](angular-eslint/angular-eslint@7e1aadf))

</details>

<details>
<summary>angular-eslint/angular-eslint (@&#8203;angular-eslint/schematics)</summary>

### [`v14.4.0`](https://github.com/angular-eslint/angular-eslint/blob/HEAD/packages/schematics/CHANGELOG.md#&#8203;1440-httpsgithubcomangular-eslintangular-eslintcomparev1431v1440-2022-11-20)

[Compare Source](angular-eslint/angular-eslint@v14.3.1...v14.4.0)

**Note:** Version bump only for package [@&#8203;angular-eslint/schematics](https://github.com/angular-eslint/schematics)

#### [14.3.1](angular-eslint/angular-eslint@v14.3.0...v14.3.1) (2022-11-20)

##### Bug Fixes

-   update dependency eslint to v8.28.0 ([#&#8203;1210](angular-eslint/angular-eslint#1210)) ([c671e74](angular-eslint/angular-eslint@c671e74))

### [`v14.3.1`](https://github.com/angular-eslint/angular-eslint/blob/HEAD/packages/schematics/CHANGELOG.md#&#8203;1431-httpsgithubcomangular-eslintangular-eslintcomparev1430v1431-2022-11-20)

[Compare Source](angular-eslint/angular-eslint@v14.3.0...v14.3.1)

##### Bug Fixes

-   update dependency eslint to v8.28.0 ([#&#8203;1210](angular-eslint/angular-eslint#1210)) ([c671e74](angular-eslint/angular-eslint@c671e74))

### [`v14.3.0`](https://github.com/angular-eslint/angular-eslint/blob/HEAD/packages/schematics/CHANGELOG.md#&#8203;1430-httpsgithubcomangular-eslintangular-eslintcomparev1420v1430-2022-11-17)

[Compare Source](angular-eslint/angular-eslint@v14.2.0...v14.3.0)

**Note:** Version bump only for package [@&#8203;angular-eslint/schematics](https://github.com/angular-eslint/schematics)

</details>

<details>
<summary>angular-eslint/angular-eslint (@&#8203;angular-eslint/template-parser)</summary>

### [`v14.4.0`](https://github.com/angular-eslint/angular-eslint/blob/HEAD/packages/template-parser/CHANGELOG.md#&#8203;1440-httpsgithubcomangular-eslintangular-eslintcomparev1431v1440-2022-11-20)

[Compare Source](angular-eslint/angular-eslint@v14.3.1...v14.4.0)

**Note:** Version bump only for package [@&#8203;angular-eslint/template-parser](https://github.com/angular-eslint/template-parser)

#### [14.3.1](angular-eslint/angular-eslint@v14.3.0...v14.3.1) (2022-11-20)

**Note:** Version bump only for package [@&#8203;angular-eslint/template-parser](https://github.com/angular-eslint/template-parser)

### [`v14.3.1`](https://github.com/angular-eslint/angular-eslint/blob/HEAD/packages/template-parser/CHANGELOG.md#&#8203;1431-httpsgithubcomangular-eslintangular-eslintcomparev1430v1431-2022-11-20)

[Compare Source](angular-eslint/angular-eslint@v14.3.0...v14.3.1)

**Note:** Version bump only for package [@&#8203;angular-eslint/template-parser](https://github.com/angular-eslint/template-parser)

### [`v14.3.0`](https://github.com/angular-eslint/angular-eslint/blob/HEAD/packages/template-parser/CHANGELOG.md#&#8203;1430-httpsgithubcomangular-eslintangular-eslintcomparev1420v1430-2022-11-17)

[Compare Source](angular-eslint/angular-eslint@v14.2.0...v14.3.0)

**Note:** Version bump only for package [@&#8203;angular-eslint/template-parser](https://github.com/angular-eslint/template-parser)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4yNi4zIiwidXBkYXRlZEluVmVyIjoiMzQuMjkuMiJ9-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1648
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
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.

Export getTemplateParserServices and ParserServices to allow writing custom template rules
2 participants