-
Notifications
You must be signed in to change notification settings - Fork 62
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: create ESLint plugin for Griffel #99
Conversation
📊 Bundle size reportUnchanged fixtures
|
// This collection is a map simply for faster access when checking if a CSS property is unsupported | ||
// @griffel/core has the same definition, but ESLint plugin should not depend on it | ||
const UNSUPPORTED_CSS_PROPERTIES: Record<keyof CSS.StandardShorthandProperties, true> = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's nonsense to have there dependency on @griffel/core
, so unfortunately - copy-paste.
e9934fd
to
e539a67
Compare
export const isIdentifier: IsHelper<AST_NODE_TYPES.Identifier> = ASTUtils.isIdentifier; | ||
export const isObjectExpression: IsHelper<AST_NODE_TYPES.ObjectExpression> = ASTUtils.isNodeOfType( | ||
AST_NODE_TYPES.ObjectExpression, | ||
); | ||
export const isProperty: IsHelper<AST_NODE_TYPES.Property> = ASTUtils.isNodeOfType(AST_NODE_TYPES.Property); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e539a67
to
c9c2fb7
Compare
@@ -65,4 +65,5 @@ export type { | |||
GriffelRenderer, | |||
} from './types'; | |||
|
|||
// Private exports, are used by devtools |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe prefix with @internal
and then strip on build and use stripInternal
in the tsconfig ?
you'll be able to use it with aliases in the monorepo but the types will be stripped on build
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't know about stripInternal
, it's a good idea. I will try it in another PR.
if (isProperty(propertyNode)) { | ||
if (isIdentifier(propertyNode.key) && !isRoot) { | ||
if (Object.prototype.hasOwnProperty.call(UNSUPPORTED_CSS_PROPERTIES, propertyNode.key.name)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: these nested if blocks can just be reduced to a single one right ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but IMO it's more readable
@@ -0,0 +1,11 @@ | |||
import { AST_NODE_TYPES, ASTUtils, TSESTree } from '@typescript-eslint/utils'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it necessary to use typescript-eslint to create the lint rule ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK there are no similar utils in ESLint itself. I was using eslint-plugin-testing-library as a reference.
This PR adds
@griffel/eslint-plugin
with a single ESLint rule to enforce usage of CSS longhands.Fixes #76.
Rule Details
Griffel does not support usage of CSS shorthands, microsoft/griffel#30.
This is enforced by typings, but there are cases when they don't work as expected microsoft/griffel#78.
Examples of incorrect code for this rule:
Examples of correct code for this rule: