@atlaskit/eslint-plugin-ui-styling-standard 0.5.1 → 0.6.0
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 +12 -0
- package/LICENSE +13 -0
- package/README.md +1 -0
- package/constellation/index/overview.mdx +1 -0
- package/constellation/no-classname-prop/usage.mdx +38 -0
- package/dist/cjs/presets/all.codegen.js +2 -1
- package/dist/cjs/presets/recommended.codegen.js +2 -1
- package/dist/cjs/rules/index.codegen.js +3 -1
- package/dist/cjs/rules/no-classname-prop/index.js +38 -0
- package/dist/es2019/presets/all.codegen.js +2 -1
- package/dist/es2019/presets/recommended.codegen.js +2 -1
- package/dist/es2019/rules/index.codegen.js +3 -1
- package/dist/es2019/rules/no-classname-prop/index.js +32 -0
- package/dist/esm/presets/all.codegen.js +2 -1
- package/dist/esm/presets/recommended.codegen.js +2 -1
- package/dist/esm/rules/index.codegen.js +3 -1
- package/dist/esm/rules/no-classname-prop/index.js +32 -0
- package/dist/types/index.codegen.d.ts +2 -0
- package/dist/types/presets/all.codegen.d.ts +2 -1
- package/dist/types/presets/recommended.codegen.d.ts +2 -1
- package/dist/types/rules/index.codegen.d.ts +1 -0
- package/dist/types/rules/no-classname-prop/index.d.ts +2 -0
- package/dist/types-ts4.5/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
- package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
- package/dist/types-ts4.5/rules/no-classname-prop/index.d.ts +2 -0
- package/package.json +3 -2
- package/src/presets/all.codegen.tsx +2 -1
- package/src/presets/recommended.codegen.tsx +2 -1
- package/src/rules/index.codegen.tsx +3 -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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-ui-styling-standard
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#81459](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/81459) [`08abd3b15614`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/08abd3b15614) - Adds `no-classname-prop` rule which prevents the use of `className` in JSX.
|
|
8
|
+
|
|
9
|
+
## 0.5.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#81702](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/81702) [`04e7850f449c`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/04e7850f449c) - Adding a missing LICENSE for this package, updating from "UNLICENSED" to make it clear this is available for use.
|
|
14
|
+
|
|
3
15
|
## 0.5.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2021-Present Atlassian Pty Ltd
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ Not intended for use outside the Atlassian frontend repository.
|
|
|
14
14
|
| Rule | Description | Recommended | Fixable | Suggestions |
|
|
15
15
|
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- | ------- | ----------- |
|
|
16
16
|
| <a href="./src/rules/local-cx-xcss/README.md">local-cx-xcss</a> | Ensures the cx() function, which is part of the XCSS API, is only used within the xcss prop. This aids tracking what styles are applied to a jsx element. | Yes | | |
|
|
17
|
+
| <a href="./src/rules/no-classname-prop/README.md">no-classname-prop</a> | Disallows usage of the `className` prop in JSX | Yes | | |
|
|
17
18
|
| <a href="./src/rules/no-important-styles/README.md">no-important-styles</a> | Disallows important style declarations | Yes | | |
|
|
18
19
|
| <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/consistent-css-prop-usage/usage">@atlaskit/design-system/consistent-css-prop-usage</a> | Ensures consistency with `css` and `xcss` prop usages | Yes | Yes | |
|
|
19
20
|
| <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-css-tagged-template-expression/usage">@atlaskit/design-system/no-css-tagged-template-expression</a> | Disallows any `css` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
|
|
@@ -12,6 +12,7 @@ but more are planned to support the standard over time.
|
|
|
12
12
|
| Rule | Description | Recommended | Fixable | Suggestions |
|
|
13
13
|
| --------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- | ------- | ----------- |
|
|
14
14
|
| <a href="local-cx-xcss/usage">local-cx-xcss</a> | Ensures the cx() function, which is part of the XCSS API, is only used within the xcss prop. This aids tracking what styles are applied to a jsx element. | Yes | | |
|
|
15
|
+
| <a href="no-classname-prop/usage">no-classname-prop</a> | Disallows usage of the `className` prop in JSX | Yes | | |
|
|
15
16
|
| <a href="no-important-styles/usage">no-important-styles</a> | Disallows important style declarations | Yes | | |
|
|
16
17
|
| <a href="consistent-css-prop-usage/usage">@atlaskit/design-system/consistent-css-prop-usage</a> | Ensures consistency with `css` and `xcss` prop usages | Yes | Yes | |
|
|
17
18
|
| <a href="no-css-tagged-template-expression/usage">@atlaskit/design-system/no-css-tagged-template-expression</a> | Disallows any `css` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# no-classname-prop
|
|
2
|
+
|
|
3
|
+
This rule prevents usage of the `className` prop in JSX.
|
|
4
|
+
|
|
5
|
+
Avoid `className` because it invites the use of unsafe global styles and is impossible to determine via local tooling. Use props for configuration and typical CSS-in-JS for styling or `xcss` for bounded overrides.
|
|
6
|
+
|
|
7
|
+
## Examples
|
|
8
|
+
|
|
9
|
+
### Incorrect
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
<div className="my-class">
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
<MyComponent className={isDisabled ? 'disabled' : undefined} />
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Correct
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { css } from '@compiled/react';
|
|
23
|
+
|
|
24
|
+
<div css={css({ padding: '10px' })} />;
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
<MyComponent isDisabled={isDisabled} />
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## FAQ
|
|
32
|
+
|
|
33
|
+
### What if I'm using `className` to target elements with JavaScript?
|
|
34
|
+
|
|
35
|
+
There are some cases where a selector is required to integrate with a 3rd party library,
|
|
36
|
+
such as legacy code using jQuery.
|
|
37
|
+
|
|
38
|
+
Use a `ref` if possible. Otherwise, if you _must_ have a selector, use a `data-*` attribute that gives enough context and is unique enough, for example `data-editor-table-target="true"`.
|
|
@@ -6,13 +6,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
9
|
-
* @codegen <<SignedSource::
|
|
9
|
+
* @codegen <<SignedSource::c07fea97418b1622081bbb5719e7aa5f>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
13
13
|
plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
|
|
14
14
|
rules: {
|
|
15
15
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
16
|
+
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
16
17
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
17
18
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
18
19
|
excludeReactComponents: true
|
|
@@ -6,13 +6,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
9
|
-
* @codegen <<SignedSource::
|
|
9
|
+
* @codegen <<SignedSource::c07fea97418b1622081bbb5719e7aa5f>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
13
13
|
plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
|
|
14
14
|
rules: {
|
|
15
15
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
16
|
+
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
16
17
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
17
18
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
18
19
|
excludeReactComponents: true
|
|
@@ -6,13 +6,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _localCxXcss = _interopRequireDefault(require("./local-cx-xcss"));
|
|
9
|
+
var _noClassnameProp = _interopRequireDefault(require("./no-classname-prop"));
|
|
9
10
|
var _noImportantStyles = _interopRequireDefault(require("./no-important-styles"));
|
|
10
11
|
/**
|
|
11
12
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
12
|
-
* @codegen <<SignedSource::
|
|
13
|
+
* @codegen <<SignedSource::a9694abdbf4245b64030b1bd2dfd9dc7>>
|
|
13
14
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
14
15
|
*/
|
|
15
16
|
var _default = exports.default = {
|
|
16
17
|
'local-cx-xcss': _localCxXcss.default,
|
|
18
|
+
'no-classname-prop': _noClassnameProp.default,
|
|
17
19
|
'no-important-styles': _noImportantStyles.default
|
|
18
20
|
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.rule = exports.default = void 0;
|
|
7
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
|
+
var _createRule = require("../utils/create-rule");
|
|
9
|
+
var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
10
|
+
meta: {
|
|
11
|
+
name: 'no-classname-prop',
|
|
12
|
+
docs: {
|
|
13
|
+
description: 'Disallows usage of the `className` prop in JSX',
|
|
14
|
+
recommended: true,
|
|
15
|
+
severity: 'warn'
|
|
16
|
+
},
|
|
17
|
+
messages: {
|
|
18
|
+
'no-classname-prop': 'Avoid `className` because it invites the use of unsafe global styles and is impossible to determine via local tooling.'
|
|
19
|
+
},
|
|
20
|
+
type: 'problem'
|
|
21
|
+
},
|
|
22
|
+
create: function create(context) {
|
|
23
|
+
return {
|
|
24
|
+
JSXAttribute: function JSXAttribute(node) {
|
|
25
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXAttribute')) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (node.name.name === 'className') {
|
|
29
|
+
context.report({
|
|
30
|
+
node: node,
|
|
31
|
+
messageId: 'no-classname-prop'
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
var _default = exports.default = rule;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::c07fea97418b1622081bbb5719e7aa5f>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
7
7
|
plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
|
|
8
8
|
rules: {
|
|
9
9
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
10
|
+
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
10
11
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
11
12
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
12
13
|
excludeReactComponents: true
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::c07fea97418b1622081bbb5719e7aa5f>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
7
7
|
plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
|
|
8
8
|
rules: {
|
|
9
9
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
10
|
+
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
10
11
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
11
12
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
12
13
|
excludeReactComponents: true
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::a9694abdbf4245b64030b1bd2dfd9dc7>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import localCxXcss from './local-cx-xcss';
|
|
7
|
+
import noClassnameProp from './no-classname-prop';
|
|
7
8
|
import noImportantStyles from './no-important-styles';
|
|
8
9
|
export default {
|
|
9
10
|
'local-cx-xcss': localCxXcss,
|
|
11
|
+
'no-classname-prop': noClassnameProp,
|
|
10
12
|
'no-important-styles': noImportantStyles
|
|
11
13
|
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
+
import { createLintRule } from '../utils/create-rule';
|
|
3
|
+
export const rule = createLintRule({
|
|
4
|
+
meta: {
|
|
5
|
+
name: 'no-classname-prop',
|
|
6
|
+
docs: {
|
|
7
|
+
description: 'Disallows usage of the `className` prop in JSX',
|
|
8
|
+
recommended: true,
|
|
9
|
+
severity: 'warn'
|
|
10
|
+
},
|
|
11
|
+
messages: {
|
|
12
|
+
'no-classname-prop': 'Avoid `className` because it invites the use of unsafe global styles and is impossible to determine via local tooling.'
|
|
13
|
+
},
|
|
14
|
+
type: 'problem'
|
|
15
|
+
},
|
|
16
|
+
create(context) {
|
|
17
|
+
return {
|
|
18
|
+
JSXAttribute(node) {
|
|
19
|
+
if (!isNodeOfType(node, 'JSXAttribute')) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (node.name.name === 'className') {
|
|
23
|
+
context.report({
|
|
24
|
+
node,
|
|
25
|
+
messageId: 'no-classname-prop'
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
export default rule;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::c07fea97418b1622081bbb5719e7aa5f>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
7
7
|
plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
|
|
8
8
|
rules: {
|
|
9
9
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
10
|
+
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
10
11
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
11
12
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
12
13
|
excludeReactComponents: true
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::c07fea97418b1622081bbb5719e7aa5f>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
7
7
|
plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
|
|
8
8
|
rules: {
|
|
9
9
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
10
|
+
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
10
11
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
11
12
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
12
13
|
excludeReactComponents: true
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::a9694abdbf4245b64030b1bd2dfd9dc7>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import localCxXcss from './local-cx-xcss';
|
|
7
|
+
import noClassnameProp from './no-classname-prop';
|
|
7
8
|
import noImportantStyles from './no-important-styles';
|
|
8
9
|
export default {
|
|
9
10
|
'local-cx-xcss': localCxXcss,
|
|
11
|
+
'no-classname-prop': noClassnameProp,
|
|
10
12
|
'no-important-styles': noImportantStyles
|
|
11
13
|
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
+
import { createLintRule } from '../utils/create-rule';
|
|
3
|
+
export var rule = createLintRule({
|
|
4
|
+
meta: {
|
|
5
|
+
name: 'no-classname-prop',
|
|
6
|
+
docs: {
|
|
7
|
+
description: 'Disallows usage of the `className` prop in JSX',
|
|
8
|
+
recommended: true,
|
|
9
|
+
severity: 'warn'
|
|
10
|
+
},
|
|
11
|
+
messages: {
|
|
12
|
+
'no-classname-prop': 'Avoid `className` because it invites the use of unsafe global styles and is impossible to determine via local tooling.'
|
|
13
|
+
},
|
|
14
|
+
type: 'problem'
|
|
15
|
+
},
|
|
16
|
+
create: function create(context) {
|
|
17
|
+
return {
|
|
18
|
+
JSXAttribute: function JSXAttribute(node) {
|
|
19
|
+
if (!isNodeOfType(node, 'JSXAttribute')) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (node.name.name === 'className') {
|
|
23
|
+
context.report({
|
|
24
|
+
node: node,
|
|
25
|
+
messageId: 'no-classname-prop'
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
export default rule;
|
|
@@ -4,6 +4,7 @@ export declare const configs: {
|
|
|
4
4
|
plugins: string[];
|
|
5
5
|
rules: {
|
|
6
6
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
7
|
+
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
7
8
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
8
9
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
9
10
|
excludeReactComponents: boolean;
|
|
@@ -33,6 +34,7 @@ export declare const configs: {
|
|
|
33
34
|
plugins: string[];
|
|
34
35
|
rules: {
|
|
35
36
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
37
|
+
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
36
38
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
37
39
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
38
40
|
excludeReactComponents: boolean;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::c07fea97418b1622081bbb5719e7aa5f>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
7
7
|
plugins: string[];
|
|
8
8
|
rules: {
|
|
9
9
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
10
|
+
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
10
11
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
11
12
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
12
13
|
excludeReactComponents: boolean;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::c07fea97418b1622081bbb5719e7aa5f>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
7
7
|
plugins: string[];
|
|
8
8
|
rules: {
|
|
9
9
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
10
|
+
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
10
11
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
11
12
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
12
13
|
excludeReactComponents: boolean;
|
|
@@ -4,6 +4,7 @@ export declare const configs: {
|
|
|
4
4
|
plugins: string[];
|
|
5
5
|
rules: {
|
|
6
6
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
7
|
+
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
7
8
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
8
9
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
9
10
|
excludeReactComponents: boolean;
|
|
@@ -33,6 +34,7 @@ export declare const configs: {
|
|
|
33
34
|
plugins: string[];
|
|
34
35
|
rules: {
|
|
35
36
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
37
|
+
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
36
38
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
37
39
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
38
40
|
excludeReactComponents: boolean;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::c07fea97418b1622081bbb5719e7aa5f>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
7
7
|
plugins: string[];
|
|
8
8
|
rules: {
|
|
9
9
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
10
|
+
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
10
11
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
11
12
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
12
13
|
excludeReactComponents: boolean;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::c07fea97418b1622081bbb5719e7aa5f>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
7
7
|
plugins: string[];
|
|
8
8
|
rules: {
|
|
9
9
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
10
|
+
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
10
11
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
11
12
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
12
13
|
excludeReactComponents: boolean;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/eslint-plugin-ui-styling-standard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"author": "Atlassian Pty Ltd",
|
|
5
5
|
"description": "The eslint plugin to enforce and educate on Atlassian's UI Styling Standard",
|
|
6
|
-
"license": "
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
7
|
"atlassian": {
|
|
8
8
|
"team": "Design System Team",
|
|
9
9
|
"inPublicMirror": true,
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@babel/runtime": "^7.0.0",
|
|
40
40
|
"@typescript-eslint/utils": "^5.48.1",
|
|
41
|
+
"eslint-codemod-utils": "^1.8.6",
|
|
41
42
|
"estraverse": "^5.3.0"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::c07fea97418b1622081bbb5719e7aa5f>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -11,6 +11,7 @@ export default {
|
|
|
11
11
|
],
|
|
12
12
|
rules: {
|
|
13
13
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
14
|
+
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
14
15
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
15
16
|
'@atlaskit/design-system/consistent-css-prop-usage': [
|
|
16
17
|
'warn',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::c07fea97418b1622081bbb5719e7aa5f>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -11,6 +11,7 @@ export default {
|
|
|
11
11
|
],
|
|
12
12
|
rules: {
|
|
13
13
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
14
|
+
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
14
15
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
15
16
|
'@atlaskit/design-system/consistent-css-prop-usage': [
|
|
16
17
|
'warn',
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::a9694abdbf4245b64030b1bd2dfd9dc7>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import localCxXcss from './local-cx-xcss';
|
|
7
|
+
import noClassnameProp from './no-classname-prop';
|
|
7
8
|
import noImportantStyles from './no-important-styles';
|
|
8
9
|
|
|
9
10
|
export default {
|
|
10
11
|
'local-cx-xcss': localCxXcss,
|
|
12
|
+
'no-classname-prop': noClassnameProp,
|
|
11
13
|
'no-important-styles': noImportantStyles,
|
|
12
14
|
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
This rule prevents usage of the `className` prop in JSX.
|
|
2
|
+
|
|
3
|
+
Avoid `className` because it invites the use of unsafe global styles and is impossible to determine via local tooling. Use props for configuration and typical CSS-in-JS for styling or `xcss` for bounded overrides.
|
|
4
|
+
|
|
5
|
+
## Examples
|
|
6
|
+
|
|
7
|
+
### Incorrect
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
<div className="my-class">
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
<MyComponent className={isDisabled ? 'disabled' : undefined} />
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Correct
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { css } from '@compiled/react';
|
|
21
|
+
|
|
22
|
+
<div css={css({ padding: '10px' })} />;
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
<MyComponent isDisabled={isDisabled} />
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## FAQ
|
|
30
|
+
|
|
31
|
+
### What if I'm using `className` to target elements with JavaScript?
|
|
32
|
+
|
|
33
|
+
There are some cases where a selector is required to integrate with a 3rd party library,
|
|
34
|
+
such as legacy code using jQuery.
|
|
35
|
+
|
|
36
|
+
Use a `ref` if possible. Otherwise, if you _must_ have a selector, use a `data-*` attribute that gives enough context and is unique enough, for example `data-editor-table-target="true"`.
|
|
@@ -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;
|