@atlaskit/eslint-plugin-platform 0.9.0 → 0.10.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 +9 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/rules/use-entrypoints-in-examples/index.js +43 -0
- package/dist/es2019/index.js +2 -0
- package/dist/es2019/rules/use-entrypoints-in-examples/index.js +37 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/rules/use-entrypoints-in-examples/index.js +37 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/rules/use-entrypoints-in-examples/index.d.ts +3 -0
- package/dist/types-ts4.5/index.d.ts +1 -0
- package/dist/types-ts4.5/rules/use-entrypoints-in-examples/index.d.ts +3 -0
- package/package.json +1 -1
- package/src/index.tsx +2 -0
- package/src/rules/use-entrypoints-in-examples/README.md +27 -0
- package/src/rules/use-entrypoints-in-examples/__tests__/rule.test.tsx +34 -0
- package/src/rules/use-entrypoints-in-examples/index.tsx +43 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-platform
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#151601](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/151601)
|
|
8
|
+
[`d619298dc0279`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d619298dc0279) -
|
|
9
|
+
Adds `use-entrypoints-in-examples` rule which prevents the use of relative imports from `src` in
|
|
10
|
+
examples. Instead they should use public entrypoints to ensure they reflect public API.
|
|
11
|
+
|
|
3
12
|
## 0.9.0
|
|
4
13
|
|
|
5
14
|
### Minor Changes
|
package/dist/cjs/index.js
CHANGED
|
@@ -27,6 +27,7 @@ var _noPreconditioning = _interopRequireDefault(require("./rules/no-precondition
|
|
|
27
27
|
var _inlineUsage = _interopRequireDefault(require("./rules/inline-usage"));
|
|
28
28
|
var _preferFg = _interopRequireDefault(require("./rules/prefer-fg"));
|
|
29
29
|
var _noAlias = _interopRequireDefault(require("./rules/no-alias"));
|
|
30
|
+
var _useEntrypointsInExamples = _interopRequireDefault(require("./rules/use-entrypoints-in-examples"));
|
|
30
31
|
var _useRecommendedUtils = _interopRequireDefault(require("./rules/use-recommended-utils"));
|
|
31
32
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
32
33
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } // eslint-disable-next-line import/no-extraneous-dependencies
|
|
@@ -52,6 +53,7 @@ var rules = exports.rules = {
|
|
|
52
53
|
'inline-usage': _inlineUsage.default,
|
|
53
54
|
'prefer-fg': _preferFg.default,
|
|
54
55
|
'no-alias': _noAlias.default,
|
|
56
|
+
'use-entrypoints-in-examples': _useEntrypointsInExamples.default,
|
|
55
57
|
'use-recommended-utils': _useRecommendedUtils.default
|
|
56
58
|
};
|
|
57
59
|
var configs = exports.configs = {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var rule = {
|
|
8
|
+
meta: {
|
|
9
|
+
docs: {
|
|
10
|
+
url: 'https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo/browse/platform/packages/platform/eslint-plugin/src/rules/use-entrypoints-in-examples/README.md',
|
|
11
|
+
description: 'Encourage usage of package entrypoints in examples.'
|
|
12
|
+
},
|
|
13
|
+
messages: {
|
|
14
|
+
useEntrypointsInExamples: 'Use the package entrypoints instead of importing from src. This ensures examples reflect public API.\n\nFor example, use `@atlaskit/button/new` instead of `../../src/new`'
|
|
15
|
+
},
|
|
16
|
+
type: 'problem'
|
|
17
|
+
},
|
|
18
|
+
create: function create(context) {
|
|
19
|
+
/**
|
|
20
|
+
* Even if it's enabled on non-example files it will ignore them.
|
|
21
|
+
*
|
|
22
|
+
* This is a defensive check, the rule should be configured to only run on examples.
|
|
23
|
+
*/
|
|
24
|
+
if (!context.filename.includes('/examples/')) {
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
ImportDeclaration: function ImportDeclaration(node) {
|
|
29
|
+
var moduleName = node.source.value;
|
|
30
|
+
if (typeof moduleName !== 'string') {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (/^(\.\.\/)+src(\/|$)/.test(moduleName)) {
|
|
34
|
+
context.report({
|
|
35
|
+
node: node.source,
|
|
36
|
+
messageId: 'useEntrypointsInExamples'
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var _default = exports.default = rule;
|
package/dist/es2019/index.js
CHANGED
|
@@ -21,6 +21,7 @@ import noPreconditioning from './rules/no-preconditioning';
|
|
|
21
21
|
import inlineUsage from './rules/inline-usage';
|
|
22
22
|
import preferFG from './rules/prefer-fg';
|
|
23
23
|
import noAlias from './rules/no-alias';
|
|
24
|
+
import useEntrypointsInExamples from './rules/use-entrypoints-in-examples';
|
|
24
25
|
import useRecommendedUtils from './rules/use-recommended-utils';
|
|
25
26
|
export const rules = {
|
|
26
27
|
'ensure-feature-flag-registration': ensureFeatureFlagRegistration,
|
|
@@ -44,6 +45,7 @@ export const rules = {
|
|
|
44
45
|
'inline-usage': inlineUsage,
|
|
45
46
|
'prefer-fg': preferFG,
|
|
46
47
|
'no-alias': noAlias,
|
|
48
|
+
'use-entrypoints-in-examples': useEntrypointsInExamples,
|
|
47
49
|
'use-recommended-utils': useRecommendedUtils
|
|
48
50
|
};
|
|
49
51
|
export const configs = {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const rule = {
|
|
2
|
+
meta: {
|
|
3
|
+
docs: {
|
|
4
|
+
url: 'https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo/browse/platform/packages/platform/eslint-plugin/src/rules/use-entrypoints-in-examples/README.md',
|
|
5
|
+
description: 'Encourage usage of package entrypoints in examples.'
|
|
6
|
+
},
|
|
7
|
+
messages: {
|
|
8
|
+
useEntrypointsInExamples: 'Use the package entrypoints instead of importing from src. This ensures examples reflect public API.\n\nFor example, use `@atlaskit/button/new` instead of `../../src/new`'
|
|
9
|
+
},
|
|
10
|
+
type: 'problem'
|
|
11
|
+
},
|
|
12
|
+
create(context) {
|
|
13
|
+
/**
|
|
14
|
+
* Even if it's enabled on non-example files it will ignore them.
|
|
15
|
+
*
|
|
16
|
+
* This is a defensive check, the rule should be configured to only run on examples.
|
|
17
|
+
*/
|
|
18
|
+
if (!context.filename.includes('/examples/')) {
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
ImportDeclaration(node) {
|
|
23
|
+
const moduleName = node.source.value;
|
|
24
|
+
if (typeof moduleName !== 'string') {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (/^(\.\.\/)+src(\/|$)/.test(moduleName)) {
|
|
28
|
+
context.report({
|
|
29
|
+
node: node.source,
|
|
30
|
+
messageId: 'useEntrypointsInExamples'
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
export default rule;
|
package/dist/esm/index.js
CHANGED
|
@@ -24,6 +24,7 @@ import noPreconditioning from './rules/no-preconditioning';
|
|
|
24
24
|
import inlineUsage from './rules/inline-usage';
|
|
25
25
|
import preferFG from './rules/prefer-fg';
|
|
26
26
|
import noAlias from './rules/no-alias';
|
|
27
|
+
import useEntrypointsInExamples from './rules/use-entrypoints-in-examples';
|
|
27
28
|
import useRecommendedUtils from './rules/use-recommended-utils';
|
|
28
29
|
export var rules = {
|
|
29
30
|
'ensure-feature-flag-registration': ensureFeatureFlagRegistration,
|
|
@@ -47,6 +48,7 @@ export var rules = {
|
|
|
47
48
|
'inline-usage': inlineUsage,
|
|
48
49
|
'prefer-fg': preferFG,
|
|
49
50
|
'no-alias': noAlias,
|
|
51
|
+
'use-entrypoints-in-examples': useEntrypointsInExamples,
|
|
50
52
|
'use-recommended-utils': useRecommendedUtils
|
|
51
53
|
};
|
|
52
54
|
export var configs = {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var rule = {
|
|
2
|
+
meta: {
|
|
3
|
+
docs: {
|
|
4
|
+
url: 'https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo/browse/platform/packages/platform/eslint-plugin/src/rules/use-entrypoints-in-examples/README.md',
|
|
5
|
+
description: 'Encourage usage of package entrypoints in examples.'
|
|
6
|
+
},
|
|
7
|
+
messages: {
|
|
8
|
+
useEntrypointsInExamples: 'Use the package entrypoints instead of importing from src. This ensures examples reflect public API.\n\nFor example, use `@atlaskit/button/new` instead of `../../src/new`'
|
|
9
|
+
},
|
|
10
|
+
type: 'problem'
|
|
11
|
+
},
|
|
12
|
+
create: function create(context) {
|
|
13
|
+
/**
|
|
14
|
+
* Even if it's enabled on non-example files it will ignore them.
|
|
15
|
+
*
|
|
16
|
+
* This is a defensive check, the rule should be configured to only run on examples.
|
|
17
|
+
*/
|
|
18
|
+
if (!context.filename.includes('/examples/')) {
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
ImportDeclaration: function ImportDeclaration(node) {
|
|
23
|
+
var moduleName = node.source.value;
|
|
24
|
+
if (typeof moduleName !== 'string') {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (/^(\.\.\/)+src(\/|$)/.test(moduleName)) {
|
|
28
|
+
context.report({
|
|
29
|
+
node: node.source,
|
|
30
|
+
messageId: 'useEntrypointsInExamples'
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
export default rule;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export declare const rules: {
|
|
|
21
21
|
'inline-usage': import("eslint").Rule.RuleModule;
|
|
22
22
|
'prefer-fg': import("eslint").Rule.RuleModule;
|
|
23
23
|
'no-alias': import("eslint").Rule.RuleModule;
|
|
24
|
+
'use-entrypoints-in-examples': import("eslint").Rule.RuleModule;
|
|
24
25
|
'use-recommended-utils': import("eslint").Rule.RuleModule;
|
|
25
26
|
};
|
|
26
27
|
export declare const configs: {
|
|
@@ -21,6 +21,7 @@ export declare const rules: {
|
|
|
21
21
|
'inline-usage': import("eslint").Rule.RuleModule;
|
|
22
22
|
'prefer-fg': import("eslint").Rule.RuleModule;
|
|
23
23
|
'no-alias': import("eslint").Rule.RuleModule;
|
|
24
|
+
'use-entrypoints-in-examples': import("eslint").Rule.RuleModule;
|
|
24
25
|
'use-recommended-utils': import("eslint").Rule.RuleModule;
|
|
25
26
|
};
|
|
26
27
|
export declare const configs: {
|
package/package.json
CHANGED
package/src/index.tsx
CHANGED
|
@@ -21,6 +21,7 @@ import noPreconditioning from './rules/no-preconditioning';
|
|
|
21
21
|
import inlineUsage from './rules/inline-usage';
|
|
22
22
|
import preferFG from './rules/prefer-fg';
|
|
23
23
|
import noAlias from './rules/no-alias';
|
|
24
|
+
import useEntrypointsInExamples from './rules/use-entrypoints-in-examples';
|
|
24
25
|
import useRecommendedUtils from './rules/use-recommended-utils';
|
|
25
26
|
|
|
26
27
|
export const rules = {
|
|
@@ -45,6 +46,7 @@ export const rules = {
|
|
|
45
46
|
'inline-usage': inlineUsage,
|
|
46
47
|
'prefer-fg': preferFG,
|
|
47
48
|
'no-alias': noAlias,
|
|
49
|
+
'use-entrypoints-in-examples': useEntrypointsInExamples,
|
|
48
50
|
'use-recommended-utils': useRecommendedUtils,
|
|
49
51
|
};
|
|
50
52
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Using public entrypoints in our examples ensures that they reflect public API.
|
|
2
|
+
|
|
3
|
+
It also has benefits for:
|
|
4
|
+
|
|
5
|
+
- readability
|
|
6
|
+
- bundle and code analysis
|
|
7
|
+
|
|
8
|
+
## Examples
|
|
9
|
+
|
|
10
|
+
This rule marks imports as violations when they reach into the `src` folder through relative file
|
|
11
|
+
paths.
|
|
12
|
+
|
|
13
|
+
### Incorrect
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import Button from '../../../src';
|
|
17
|
+
|
|
18
|
+
import { IconButton } from '../../../src/new';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Correct
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
import Button from '@atlaskit/button';
|
|
25
|
+
|
|
26
|
+
import { ExampleHelper } from '../not-src';
|
|
27
|
+
```
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { tester } from '../../../__tests__/utils/_tester';
|
|
2
|
+
import rule from '../index';
|
|
3
|
+
|
|
4
|
+
const exampleFilename = 'packages/design-system/button/examples/0-basic.tsx';
|
|
5
|
+
const nonExampleFilename = 'packages/design-system/button/scripts/my-script.tsx';
|
|
6
|
+
|
|
7
|
+
tester.run('use-entrypoints-in-examples', rule, {
|
|
8
|
+
valid: [
|
|
9
|
+
{
|
|
10
|
+
code: `import Button from '@atlaskit/button';`,
|
|
11
|
+
filename: exampleFilename,
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
code: `import { ExampleHelper } from '../not-src';`,
|
|
15
|
+
filename: exampleFilename,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
code: `import Button from '../src';`,
|
|
19
|
+
filename: nonExampleFilename,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
invalid: [
|
|
23
|
+
{
|
|
24
|
+
code: `import Button from '../../../src';`,
|
|
25
|
+
filename: exampleFilename,
|
|
26
|
+
errors: [{ messageId: 'useEntrypointsInExamples' }],
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
code: `import { IconButton } from '../../../src/new';`,
|
|
30
|
+
filename: exampleFilename,
|
|
31
|
+
errors: [{ messageId: 'useEntrypointsInExamples' }],
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
|
|
3
|
+
const rule: Rule.RuleModule = {
|
|
4
|
+
meta: {
|
|
5
|
+
docs: {
|
|
6
|
+
url: 'https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo/browse/platform/packages/platform/eslint-plugin/src/rules/use-entrypoints-in-examples/README.md',
|
|
7
|
+
description: 'Encourage usage of package entrypoints in examples.',
|
|
8
|
+
},
|
|
9
|
+
messages: {
|
|
10
|
+
useEntrypointsInExamples:
|
|
11
|
+
'Use the package entrypoints instead of importing from src. This ensures examples reflect public API.\n\nFor example, use `@atlaskit/button/new` instead of `../../src/new`',
|
|
12
|
+
},
|
|
13
|
+
type: 'problem',
|
|
14
|
+
},
|
|
15
|
+
create(context) {
|
|
16
|
+
/**
|
|
17
|
+
* Even if it's enabled on non-example files it will ignore them.
|
|
18
|
+
*
|
|
19
|
+
* This is a defensive check, the rule should be configured to only run on examples.
|
|
20
|
+
*/
|
|
21
|
+
if (!context.filename.includes('/examples/')) {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
ImportDeclaration(node) {
|
|
27
|
+
const moduleName = node.source.value;
|
|
28
|
+
if (typeof moduleName !== 'string') {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (/^(\.\.\/)+src(\/|$)/.test(moduleName)) {
|
|
33
|
+
context.report({
|
|
34
|
+
node: node.source,
|
|
35
|
+
messageId: 'useEntrypointsInExamples',
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export default rule;
|