Skip to content

Commit ad101dd

Browse files
committed
feat(lint): add rules to disallow slotted popovers and tailwind classes
- `no-slotted-popovers` to prevent the use of the slot attribute on popover elements - `no-tailwind-classes` to disallow Tailwind CSS utility classes on nve custom elements Signed-off-by: Cory Rylan <crylan@nvidia.com>
1 parent 9b5509f commit ad101dd

10 files changed

Lines changed: 1432 additions & 9 deletions

File tree

projects/core/src/page/page.examples.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ export const InteractionDrawer = {
620620
<p nve-text="body">page content</p>
621621
</main>
622622
623-
<nve-drawer id="drawer" slot="left-aside" position="left" size="sm" closable style="--top: 48px">
623+
<nve-drawer id="drawer" position="left" size="sm" closable style="--top: 48px">
624624
<nve-drawer-header>
625625
<h3 nve-text="heading medium sm">Drawer Header</h3>
626626
</nve-drawer-header>

projects/lint/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ export default [
8383
| `@nvidia-elements/lint/no-nested-container-types` | Require nested container components to use flat container mode. | HTML | `error` |
8484
| `@nvidia-elements/lint/no-restricted-attributes` | Disallow use of invalid API attributes or utility attributes on custom HTML element tags. | HTML | `error` |
8585
| `@nvidia-elements/lint/no-restricted-page-sizing` | Disallow custom height or width styles on nve-page. | HTML | `error` |
86+
| `@nvidia-elements/lint/no-slotted-popovers` | Disallow the slot attribute on popover elements (nve-tooltip, nve-dialog, nve-drawer, ...). | HTML | `error` |
87+
| `@nvidia-elements/lint/no-tailwind-classes` | Disallow Tailwind CSS utility classes with Elements alternatives, and all Tailwind utilities on nve custom elements. | HTML | `warn` |
8688
| `@nvidia-elements/lint/no-unexpected-attribute-value` | Disallow use of invalid attribute values for nve-* elements. | HTML | `error` |
8789
| `@nvidia-elements/lint/no-unexpected-css-value` | Disallow use of invalid CSS values. | CSS | `error` |
8890
| `@nvidia-elements/lint/no-unexpected-css-variable` | Disallow use of invalid CSS theme variables. | CSS | `error` |

projects/lint/src/eslint/configs/html.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import noUnexpectedStyleCustomization from '../rules/no-unexpected-style-customi
1313
import noDeprecatedGlobalAttributeValue from '../rules/no-deprecated-global-attribute-value.js';
1414
import noDeprecatedGlobalAttributes from '../rules/no-deprecated-global-attributes.js';
1515
import noRestrictedAttributes from '../rules/no-restricted-attributes.js';
16+
import noSlottedPopovers from '../rules/no-slotted-popovers.js';
1617
import noDeprecatedSlots from '../rules/no-deprecated-slots.js';
1718
import noMissingSlottedElements from '../rules/no-missing-slotted-elements.js';
1819
import noMissingControlLabel from '../rules/no-missing-control-label.js';
@@ -29,6 +30,7 @@ import noUnknownCssVariable from '../rules/no-unknown-css-variable.js';
2930
import noRestrictedPageSizing from '../rules/no-restricted-page-sizing.js';
3031
import noNestedContainerTypes from '../rules/no-nested-container-types.js';
3132
import noUnstyledTypography from '../rules/no-unstyled-typography.js';
33+
import noTailwindClasses from '../rules/no-tailwind-classes.js';
3234

3335
const source = ['src/**/*.html', 'src/**/*.js', 'src/**/*.ts', 'src/**/*.tsx'];
3436

@@ -71,6 +73,7 @@ export const elementsHtmlConfig: Linter.Config = {
7173
'no-missing-popover-trigger': noMissingPopoverTrigger,
7274
'no-restricted-attributes': noRestrictedAttributes,
7375
'no-restricted-page-sizing': noRestrictedPageSizing,
76+
'no-slotted-popovers': noSlottedPopovers,
7477
'no-unexpected-global-attribute-value': noUnexpectedGlobalAttributeValue,
7578
'no-unexpected-style-customization': noUnexpectedStyleCustomization,
7679
'no-unexpected-slot-value': noUnexpectedSlotValue,
@@ -82,13 +85,13 @@ export const elementsHtmlConfig: Linter.Config = {
8285
'no-missing-gap-space': noMissingGapSpace,
8386
'no-unknown-css-variable': noUnknownCssVariable,
8487
'no-nested-container-types': noNestedContainerTypes,
85-
'no-unstyled-typography': noUnstyledTypography
88+
'no-unstyled-typography': noUnstyledTypography,
89+
'no-tailwind-classes': noTailwindClasses
8690
}
8791
}
8892
},
8993
rules: {
9094
'@nvidia-elements/lint/no-complex-popovers': ['error'],
91-
'@nvidia-elements/lint/no-unexpected-style-customization': ['off'],
9295
'@nvidia-elements/lint/no-deprecated-tags': ['error'],
9396
'@nvidia-elements/lint/no-deprecated-attributes': ['error'],
9497
'@nvidia-elements/lint/no-deprecated-icon-names': ['error'],
@@ -102,16 +105,19 @@ export const elementsHtmlConfig: Linter.Config = {
102105
'@nvidia-elements/lint/no-missing-popover-trigger': ['error'],
103106
'@nvidia-elements/lint/no-restricted-attributes': ['error'],
104107
'@nvidia-elements/lint/no-restricted-page-sizing': ['error'],
108+
'@nvidia-elements/lint/no-slotted-popovers': ['error'],
105109
'@nvidia-elements/lint/no-unexpected-global-attribute-value': ['error'],
106110
'@nvidia-elements/lint/no-unexpected-slot-value': ['error'],
107111
'@nvidia-elements/lint/no-unknown-tags': ['error'],
108112
'@nvidia-elements/lint/no-unexpected-attribute-value': ['error'],
109113
'@nvidia-elements/lint/no-unexpected-input-type': ['error'],
110114
'@nvidia-elements/lint/no-invalid-event-listeners': ['error'],
111115
'@nvidia-elements/lint/no-invalid-invoker-triggers': ['error'],
112-
'@nvidia-elements/lint/no-missing-gap-space': ['off'],
113116
'@nvidia-elements/lint/no-unknown-css-variable': ['error'],
114117
'@nvidia-elements/lint/no-nested-container-types': ['error'],
115-
'@nvidia-elements/lint/no-unstyled-typography': ['error']
118+
'@nvidia-elements/lint/no-unstyled-typography': ['error'],
119+
'@nvidia-elements/lint/no-tailwind-classes': ['error'],
120+
'@nvidia-elements/lint/no-unexpected-style-customization': ['off'],
121+
'@nvidia-elements/lint/no-missing-gap-space': ['off']
116122
}
117123
};

projects/lint/src/eslint/internals/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,23 @@ export interface TemplateLintMessage {
2626

2727
export async function lintPlaygroundTemplate(code: string): Promise<TemplateLintMessage[]> {
2828
// extra restrictions/rules as agents rarely use these advanced APIs correctly for playground generation out of context of an established project
29-
// '@nvidia-elements/lint/no-unexpected-style-customization': ['error']
3029
const rules: Partial<Linter.RulesRecord> = {
31-
'@nvidia-elements/lint/no-unexpected-global-attribute-value': ['error', { distilled: true }],
30+
'@nvidia-elements/lint/no-unexpected-style-customization': ['error'],
31+
'@nvidia-elements/lint/no-missing-gap-space': ['error'],
3232
'@nvidia-elements/lint/no-missing-slotted-elements': ['error', { 'nve-card': { required: ['nve-card-content'] } }],
33-
'@nvidia-elements/lint/no-missing-gap-space': ['error']
33+
'@nvidia-elements/lint/no-unexpected-global-attribute-value': ['error', { distilled: true }],
34+
'@nvidia-elements/lint/no-tailwind-classes': ['error', { strict: true }]
3435
};
3536
return lintString(code, rules);
3637
}
3738

3839
export async function lintTemplate(code: string): Promise<TemplateLintMessage[]> {
39-
return lintString(code);
40+
const rules: Partial<Linter.RulesRecord> = {
41+
'@nvidia-elements/lint/no-unexpected-global-attribute-value': ['error', { distilled: true }],
42+
'@nvidia-elements/lint/no-tailwind-classes': ['warn', { strict: true }],
43+
'@nvidia-elements/lint/no-missing-gap-space': ['warn']
44+
};
45+
return lintString(code, rules);
4046
}
4147

4248
async function lintString(code: string, rules: Partial<Linter.RulesRecord> = {}): Promise<TemplateLintMessage[]> {

0 commit comments

Comments
 (0)