@atlaskit/eslint-plugin-ui-styling-standard 0.5.2 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +16 -14
- package/constellation/convert-props-syntax/usage.mdx +115 -0
- package/constellation/index/overview.mdx +16 -14
- package/constellation/no-classname-prop/usage.mdx +38 -0
- package/dist/cjs/presets/all.codegen.js +3 -1
- package/dist/cjs/presets/recommended.codegen.js +3 -1
- package/dist/cjs/rules/convert-props-syntax/index.js +396 -0
- package/dist/cjs/rules/index.codegen.js +5 -1
- package/dist/cjs/rules/no-classname-prop/index.js +38 -0
- package/dist/cjs/rules/utils/is-supported-import.js +7 -0
- package/dist/es2019/presets/all.codegen.js +3 -1
- package/dist/es2019/presets/recommended.codegen.js +3 -1
- package/dist/es2019/rules/convert-props-syntax/index.js +291 -0
- package/dist/es2019/rules/index.codegen.js +5 -1
- package/dist/es2019/rules/no-classname-prop/index.js +32 -0
- package/dist/es2019/rules/utils/is-supported-import.js +7 -0
- package/dist/esm/presets/all.codegen.js +3 -1
- package/dist/esm/presets/recommended.codegen.js +3 -1
- package/dist/esm/rules/convert-props-syntax/index.js +389 -0
- package/dist/esm/rules/index.codegen.js +5 -1
- package/dist/esm/rules/no-classname-prop/index.js +32 -0
- package/dist/esm/rules/utils/is-supported-import.js +7 -0
- package/dist/types/index.codegen.d.ts +4 -0
- package/dist/types/presets/all.codegen.d.ts +3 -1
- package/dist/types/presets/recommended.codegen.d.ts +3 -1
- package/dist/types/rules/convert-props-syntax/index.d.ts +3 -0
- package/dist/types/rules/index.codegen.d.ts +2 -0
- package/dist/types/rules/no-classname-prop/index.d.ts +2 -0
- package/dist/types-ts4.5/index.codegen.d.ts +4 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +3 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +3 -1
- package/dist/types-ts4.5/rules/convert-props-syntax/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/rules/no-classname-prop/index.d.ts +2 -0
- package/package.json +6 -3
- package/src/presets/all.codegen.tsx +3 -1
- package/src/presets/recommended.codegen.tsx +3 -1
- package/src/rules/convert-props-syntax/README.md +113 -0
- package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +76 -0
- package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +422 -0
- package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +140 -0
- package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +69 -0
- package/src/rules/convert-props-syntax/index.tsx +414 -0
- package/src/rules/index.codegen.tsx +5 -1
- package/src/rules/no-classname-prop/README.md +36 -0
- package/src/rules/no-classname-prop/__tests__/rule.test.tsx +39 -0
- package/src/rules/no-classname-prop/index.tsx +34 -0
- package/src/rules/utils/README.md +1 -0
- package/src/rules/utils/is-supported-import.tsx +7 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { tester } from '../../__tests__/utils/_tester';
|
|
2
|
+
import rule from '../index';
|
|
3
|
+
|
|
4
|
+
tester.run('no-classname-prop', rule, {
|
|
5
|
+
valid: [
|
|
6
|
+
{
|
|
7
|
+
code: `
|
|
8
|
+
<div />
|
|
9
|
+
`,
|
|
10
|
+
},
|
|
11
|
+
],
|
|
12
|
+
invalid: [
|
|
13
|
+
{
|
|
14
|
+
// Basic test case
|
|
15
|
+
code: `
|
|
16
|
+
<div className={myStyles} />
|
|
17
|
+
`,
|
|
18
|
+
errors: [{ messageId: 'no-classname-prop' }],
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
// String
|
|
22
|
+
code: `
|
|
23
|
+
<div className="my-class" />
|
|
24
|
+
`,
|
|
25
|
+
errors: [{ messageId: 'no-classname-prop' }],
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
// With non-primitive elements
|
|
29
|
+
code: `
|
|
30
|
+
import { styled } from '@compiled/react';
|
|
31
|
+
|
|
32
|
+
const Component = styled.div({});
|
|
33
|
+
|
|
34
|
+
<Component className="my-class" />
|
|
35
|
+
`,
|
|
36
|
+
errors: [{ messageId: 'no-classname-prop' }],
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isNodeOfType, Node } from 'eslint-codemod-utils';
|
|
2
|
+
|
|
3
|
+
import { createLintRule } from '../utils/create-rule';
|
|
4
|
+
|
|
5
|
+
export const rule = createLintRule({
|
|
6
|
+
meta: {
|
|
7
|
+
name: 'no-classname-prop',
|
|
8
|
+
docs: {
|
|
9
|
+
description: 'Disallows usage of the `className` prop in JSX',
|
|
10
|
+
recommended: true,
|
|
11
|
+
severity: 'warn',
|
|
12
|
+
},
|
|
13
|
+
messages: {
|
|
14
|
+
'no-classname-prop':
|
|
15
|
+
'Avoid `className` because it invites the use of unsafe global styles and is impossible to determine via local tooling.',
|
|
16
|
+
},
|
|
17
|
+
type: 'problem',
|
|
18
|
+
},
|
|
19
|
+
create(context) {
|
|
20
|
+
return {
|
|
21
|
+
JSXAttribute(node: Node) {
|
|
22
|
+
if (!isNodeOfType(node, 'JSXAttribute')) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (node.name.name === 'className') {
|
|
27
|
+
context.report({ node, messageId: 'no-classname-prop' });
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export default rule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
This contains utility functions copied over from `packages/design-system/eslint-plugin/src/rules/utils/` until we move the relevant eslint rules over to `packages/design-system/eslint-plugin-ui-styling-standard`.
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
// This should be kept in sync with
|
|
2
|
+
// packages/design-system/eslint-plugin/src/rules/utils/is-supported-import.tsx
|
|
3
|
+
// whenever possible.
|
|
4
|
+
//
|
|
5
|
+
// TODO: would having an @atlassian/eslint-plugin-design-system-common
|
|
6
|
+
// package be useful?
|
|
7
|
+
|
|
1
8
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
9
|
import type { Rule, Scope } from 'eslint';
|
|
3
10
|
import type { CallExpression } from 'estree';
|