@atlaskit/eslint-plugin-platform 0.0.6 → 0.1.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/dist/cjs/index.js +18 -3
- package/dist/cjs/rules/ensure-test-runner-arguments/index.js +19 -8
- package/dist/cjs/rules/no-pre-post-installs/index.js +34 -0
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/index.js +13 -1
- package/dist/es2019/rules/ensure-test-runner-arguments/index.js +19 -8
- package/dist/es2019/rules/no-pre-post-installs/index.js +27 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/index.js +15 -1
- package/dist/esm/rules/ensure-test-runner-arguments/index.js +19 -8
- package/dist/esm/rules/no-pre-post-installs/index.js +27 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/index.d.ts +6 -0
- package/dist/types/rules/no-pre-post-installs/index.d.ts +3 -0
- package/package.json +1 -1
- package/report.api.md +8 -0
- package/src/index.tsx +16 -0
- package/src/rules/ensure-test-runner-arguments/__tests__/unit/rule.test.tsx +77 -0
- package/src/rules/ensure-test-runner-arguments/index.tsx +29 -5
- package/src/rules/no-pre-post-installs/__tests__/unit/rule.test.ts +41 -0
- package/src/rules/no-pre-post-installs/index.ts +34 -0
- package/tmp/api-report-tmp.d.ts +8 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-platform
|
|
2
2
|
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`6339334e3ac`](https://bitbucket.org/atlassian/atlassian-frontend/commits/6339334e3ac) - Adds new rule to disallow pre/post install scripts in package.json.
|
|
8
|
+
|
|
9
|
+
## 0.0.7
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`0cab60b90c3`](https://bitbucket.org/atlassian/atlassian-frontend/commits/0cab60b90c3) - Add fix to eslint rule on the arguments of nested test runner
|
|
14
|
+
|
|
3
15
|
## 0.0.6
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/cjs/index.js
CHANGED
|
@@ -4,8 +4,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.rules = exports.configs = void 0;
|
|
7
|
+
exports.rules = exports.processors = exports.configs = void 0;
|
|
8
8
|
var _ensureFeatureFlagRegistration = _interopRequireDefault(require("./rules/ensure-feature-flag-registration"));
|
|
9
|
+
var _noPrePostInstalls = _interopRequireDefault(require("./rules/no-pre-post-installs"));
|
|
9
10
|
var _ensureTestRunnerArguments = _interopRequireDefault(require("./rules/ensure-test-runner-arguments"));
|
|
10
11
|
var _ensureTestRunnerNestedCount = _interopRequireDefault(require("./rules/ensure-test-runner-nested-count"));
|
|
11
12
|
var _noInvalidFeatureFlagUsage = _interopRequireDefault(require("./rules/no-invalid-feature-flag-usage"));
|
|
@@ -13,7 +14,8 @@ var rules = {
|
|
|
13
14
|
'ensure-feature-flag-registration': _ensureFeatureFlagRegistration.default,
|
|
14
15
|
'ensure-test-runner-arguments': _ensureTestRunnerArguments.default,
|
|
15
16
|
'ensure-test-runner-nested-count': _ensureTestRunnerNestedCount.default,
|
|
16
|
-
'no-invalid-feature-flag-usage': _noInvalidFeatureFlagUsage.default
|
|
17
|
+
'no-invalid-feature-flag-usage': _noInvalidFeatureFlagUsage.default,
|
|
18
|
+
'no-pre-post-install-scripts': _noPrePostInstalls.default
|
|
17
19
|
};
|
|
18
20
|
exports.rules = rules;
|
|
19
21
|
var configs = {
|
|
@@ -21,10 +23,23 @@ var configs = {
|
|
|
21
23
|
plugins: ['@atlaskit/platform'],
|
|
22
24
|
rules: {
|
|
23
25
|
'@atlaskit/platform/ensure-feature-flag-registration': 'error',
|
|
26
|
+
'@atlaskit/platform/no-pre-post-install-scripts': 'error',
|
|
24
27
|
'@atlaskit/platform/ensure-test-runner-arguments': 'error',
|
|
25
28
|
'@atlaskit/platform/ensure-test-runner-nested-count': 'warn',
|
|
26
29
|
'@atlaskit/platform/no-invalid-feature-flag-usage': 'error'
|
|
27
30
|
}
|
|
28
31
|
}
|
|
29
32
|
};
|
|
30
|
-
exports.configs = configs;
|
|
33
|
+
exports.configs = configs;
|
|
34
|
+
var processors = {
|
|
35
|
+
'package-json-processor': {
|
|
36
|
+
preprocess: function preprocess(source) {
|
|
37
|
+
// augment the json into a js file
|
|
38
|
+
return ["/* eslint-disable quote-props, comma-dangle, quotes, semi, eol-last, @typescript-eslint/semi, no-template-curly-in-string */ module.exports = ".concat(source.trim())];
|
|
39
|
+
},
|
|
40
|
+
postprocess: function postprocess(errors) {
|
|
41
|
+
return errors[0];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports.processors = processors;
|
|
@@ -13,11 +13,12 @@ var rule = {
|
|
|
13
13
|
recommended: false
|
|
14
14
|
},
|
|
15
15
|
type: 'problem',
|
|
16
|
+
fixable: 'code',
|
|
16
17
|
messages: {
|
|
17
18
|
onlyInlineFeatureFlag: 'Only pass in feature flag as string literal, please replace {{identifierName}} with its value.',
|
|
18
19
|
onlyInlineTestFunction: 'Only pass in test functions/cases in an inline manner. Test functions/cases should be passed in directly, instead of as variables. Please replace {{identifierName}} with its own definition.',
|
|
19
|
-
passDownExistingFeatureFlagParam: '
|
|
20
|
-
passDownExistingFeatureFlagArgument: '
|
|
20
|
+
passDownExistingFeatureFlagParam: 'An argument symbolising existing FFs needs to be passed down as param when calling nested test runner. See examples in the package which declares this function.',
|
|
21
|
+
passDownExistingFeatureFlagArgument: 'An argument symbolising existing FFs needs to be passed in as argument when calling nested test runner. See examples in the package which declares this function.',
|
|
21
22
|
passDownExistingFeatureFlagNamesMatch: 'Argument names not matching when passing down existing feature flags. See examples in the package which declares this function.'
|
|
22
23
|
}
|
|
23
24
|
},
|
|
@@ -64,25 +65,35 @@ var rule = {
|
|
|
64
65
|
// Not pass in ff to the function that calls test runner
|
|
65
66
|
if (!node.parent.params[0] || node.parent.params[0].type !== 'Identifier') {
|
|
66
67
|
return context.report({
|
|
67
|
-
node: node,
|
|
68
|
-
messageId: 'passDownExistingFeatureFlagParam'
|
|
68
|
+
node: node.parent,
|
|
69
|
+
messageId: 'passDownExistingFeatureFlagParam',
|
|
70
|
+
fix: function fix(fixer) {
|
|
71
|
+
var parentNodeRange = node.parent.range;
|
|
72
|
+
return [fixer.replaceTextRange([parentNodeRange[0], parentNodeRange[0] + 2], 'ff'), node.arguments[3] ? fixer.replaceText(node.arguments[3], 'ff') : fixer.insertTextAfter(node.arguments[2], ', ff')];
|
|
73
|
+
}
|
|
69
74
|
});
|
|
70
75
|
}
|
|
71
76
|
|
|
72
77
|
// Not pass in ff to test runner as 4th argument
|
|
78
|
+
var paramName = node.parent.params[0].name;
|
|
73
79
|
if (!node.arguments[3] || node.arguments[3].type !== 'Identifier') {
|
|
74
80
|
return context.report({
|
|
75
81
|
node: node,
|
|
76
|
-
messageId: 'passDownExistingFeatureFlagArgument'
|
|
82
|
+
messageId: 'passDownExistingFeatureFlagArgument',
|
|
83
|
+
fix: function fix(fixer) {
|
|
84
|
+
return node.arguments[3] ? fixer.replaceText(node.arguments[3], paramName) : fixer.insertTextAfter(node.arguments[2], ", ".concat(paramName));
|
|
85
|
+
}
|
|
77
86
|
});
|
|
78
87
|
}
|
|
79
88
|
// Pass in the above two, but names don't match
|
|
80
|
-
var paramName = node.parent.params[0].name;
|
|
81
89
|
var arguName = node.arguments[3].name;
|
|
82
90
|
if (paramName !== arguName) {
|
|
83
91
|
return context.report({
|
|
84
|
-
node: node,
|
|
85
|
-
messageId: 'passDownExistingFeatureFlagNamesMatch'
|
|
92
|
+
node: node.parent,
|
|
93
|
+
messageId: 'passDownExistingFeatureFlagNamesMatch',
|
|
94
|
+
fix: function fix(fixer) {
|
|
95
|
+
return fixer.replaceText(node.arguments[3], paramName);
|
|
96
|
+
}
|
|
86
97
|
});
|
|
87
98
|
}
|
|
88
99
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var rule = {
|
|
8
|
+
meta: {
|
|
9
|
+
type: 'problem',
|
|
10
|
+
docs: {
|
|
11
|
+
description: 'This rule disallows public packages to have pre/post install scripts as installations can happen on different environments',
|
|
12
|
+
recommended: false
|
|
13
|
+
},
|
|
14
|
+
hasSuggestions: false,
|
|
15
|
+
messages: {
|
|
16
|
+
prePostInstallScriptsNotAllowed: 'pre/post install scripts not allowed in package.json'
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
create: function create(context) {
|
|
20
|
+
return {
|
|
21
|
+
'ObjectExpression Property[key.value=scripts] Property[key.value=/^(pre|post)install$/]': function ObjectExpressionPropertyKeyValueScriptsPropertyKeyValuePrePostInstall$(node) {
|
|
22
|
+
if (!context.getFilename().endsWith('/package.json')) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
return context.report({
|
|
26
|
+
node: node,
|
|
27
|
+
messageId: 'prePostInstallScriptsNotAllowed'
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var _default = rule;
|
|
34
|
+
exports.default = _default;
|
package/dist/cjs/version.json
CHANGED
package/dist/es2019/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import ensureFeatureFlagRegistration from './rules/ensure-feature-flag-registration';
|
|
2
|
+
import noPreAndPostInstallScripts from './rules/no-pre-post-installs';
|
|
2
3
|
import ensureTestRunnerArguments from './rules/ensure-test-runner-arguments';
|
|
3
4
|
import ensureTestRunnerNestedCount from './rules/ensure-test-runner-nested-count';
|
|
4
5
|
import noInvalidFeatureFlagUsage from './rules/no-invalid-feature-flag-usage';
|
|
@@ -6,16 +7,27 @@ export const rules = {
|
|
|
6
7
|
'ensure-feature-flag-registration': ensureFeatureFlagRegistration,
|
|
7
8
|
'ensure-test-runner-arguments': ensureTestRunnerArguments,
|
|
8
9
|
'ensure-test-runner-nested-count': ensureTestRunnerNestedCount,
|
|
9
|
-
'no-invalid-feature-flag-usage': noInvalidFeatureFlagUsage
|
|
10
|
+
'no-invalid-feature-flag-usage': noInvalidFeatureFlagUsage,
|
|
11
|
+
'no-pre-post-install-scripts': noPreAndPostInstallScripts
|
|
10
12
|
};
|
|
11
13
|
export const configs = {
|
|
12
14
|
recommended: {
|
|
13
15
|
plugins: ['@atlaskit/platform'],
|
|
14
16
|
rules: {
|
|
15
17
|
'@atlaskit/platform/ensure-feature-flag-registration': 'error',
|
|
18
|
+
'@atlaskit/platform/no-pre-post-install-scripts': 'error',
|
|
16
19
|
'@atlaskit/platform/ensure-test-runner-arguments': 'error',
|
|
17
20
|
'@atlaskit/platform/ensure-test-runner-nested-count': 'warn',
|
|
18
21
|
'@atlaskit/platform/no-invalid-feature-flag-usage': 'error'
|
|
19
22
|
}
|
|
20
23
|
}
|
|
24
|
+
};
|
|
25
|
+
export const processors = {
|
|
26
|
+
'package-json-processor': {
|
|
27
|
+
preprocess: source => {
|
|
28
|
+
// augment the json into a js file
|
|
29
|
+
return [`/* eslint-disable quote-props, comma-dangle, quotes, semi, eol-last, @typescript-eslint/semi, no-template-curly-in-string */ module.exports = ${source.trim()}`];
|
|
30
|
+
},
|
|
31
|
+
postprocess: errors => errors[0]
|
|
32
|
+
}
|
|
21
33
|
};
|
|
@@ -5,11 +5,12 @@ const rule = {
|
|
|
5
5
|
recommended: false
|
|
6
6
|
},
|
|
7
7
|
type: 'problem',
|
|
8
|
+
fixable: 'code',
|
|
8
9
|
messages: {
|
|
9
10
|
onlyInlineFeatureFlag: 'Only pass in feature flag as string literal, please replace {{identifierName}} with its value.',
|
|
10
11
|
onlyInlineTestFunction: 'Only pass in test functions/cases in an inline manner. Test functions/cases should be passed in directly, instead of as variables. Please replace {{identifierName}} with its own definition.',
|
|
11
|
-
passDownExistingFeatureFlagParam: '
|
|
12
|
-
passDownExistingFeatureFlagArgument: '
|
|
12
|
+
passDownExistingFeatureFlagParam: 'An argument symbolising existing FFs needs to be passed down as param when calling nested test runner. See examples in the package which declares this function.',
|
|
13
|
+
passDownExistingFeatureFlagArgument: 'An argument symbolising existing FFs needs to be passed in as argument when calling nested test runner. See examples in the package which declares this function.',
|
|
13
14
|
passDownExistingFeatureFlagNamesMatch: 'Argument names not matching when passing down existing feature flags. See examples in the package which declares this function.'
|
|
14
15
|
}
|
|
15
16
|
},
|
|
@@ -57,25 +58,35 @@ const rule = {
|
|
|
57
58
|
// Not pass in ff to the function that calls test runner
|
|
58
59
|
if (!node.parent.params[0] || node.parent.params[0].type !== 'Identifier') {
|
|
59
60
|
return context.report({
|
|
60
|
-
node,
|
|
61
|
-
messageId: 'passDownExistingFeatureFlagParam'
|
|
61
|
+
node: node.parent,
|
|
62
|
+
messageId: 'passDownExistingFeatureFlagParam',
|
|
63
|
+
fix: function (fixer) {
|
|
64
|
+
const parentNodeRange = node.parent.range;
|
|
65
|
+
return [fixer.replaceTextRange([parentNodeRange[0], parentNodeRange[0] + 2], 'ff'), node.arguments[3] ? fixer.replaceText(node.arguments[3], 'ff') : fixer.insertTextAfter(node.arguments[2], ', ff')];
|
|
66
|
+
}
|
|
62
67
|
});
|
|
63
68
|
}
|
|
64
69
|
|
|
65
70
|
// Not pass in ff to test runner as 4th argument
|
|
71
|
+
const paramName = node.parent.params[0].name;
|
|
66
72
|
if (!node.arguments[3] || node.arguments[3].type !== 'Identifier') {
|
|
67
73
|
return context.report({
|
|
68
74
|
node,
|
|
69
|
-
messageId: 'passDownExistingFeatureFlagArgument'
|
|
75
|
+
messageId: 'passDownExistingFeatureFlagArgument',
|
|
76
|
+
fix: function (fixer) {
|
|
77
|
+
return node.arguments[3] ? fixer.replaceText(node.arguments[3], paramName) : fixer.insertTextAfter(node.arguments[2], `, ${paramName}`);
|
|
78
|
+
}
|
|
70
79
|
});
|
|
71
80
|
}
|
|
72
81
|
// Pass in the above two, but names don't match
|
|
73
|
-
const paramName = node.parent.params[0].name;
|
|
74
82
|
const arguName = node.arguments[3].name;
|
|
75
83
|
if (paramName !== arguName) {
|
|
76
84
|
return context.report({
|
|
77
|
-
node,
|
|
78
|
-
messageId: 'passDownExistingFeatureFlagNamesMatch'
|
|
85
|
+
node: node.parent,
|
|
86
|
+
messageId: 'passDownExistingFeatureFlagNamesMatch',
|
|
87
|
+
fix: function (fixer) {
|
|
88
|
+
return fixer.replaceText(node.arguments[3], paramName);
|
|
89
|
+
}
|
|
79
90
|
});
|
|
80
91
|
}
|
|
81
92
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const rule = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: 'problem',
|
|
4
|
+
docs: {
|
|
5
|
+
description: 'This rule disallows public packages to have pre/post install scripts as installations can happen on different environments',
|
|
6
|
+
recommended: false
|
|
7
|
+
},
|
|
8
|
+
hasSuggestions: false,
|
|
9
|
+
messages: {
|
|
10
|
+
prePostInstallScriptsNotAllowed: 'pre/post install scripts not allowed in package.json'
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
create(context) {
|
|
14
|
+
return {
|
|
15
|
+
'ObjectExpression Property[key.value=scripts] Property[key.value=/^(pre|post)install$/]': node => {
|
|
16
|
+
if (!context.getFilename().endsWith('/package.json')) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
return context.report({
|
|
20
|
+
node,
|
|
21
|
+
messageId: 'prePostInstallScriptsNotAllowed'
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
export default rule;
|
package/dist/es2019/version.json
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import ensureFeatureFlagRegistration from './rules/ensure-feature-flag-registration';
|
|
2
|
+
import noPreAndPostInstallScripts from './rules/no-pre-post-installs';
|
|
2
3
|
import ensureTestRunnerArguments from './rules/ensure-test-runner-arguments';
|
|
3
4
|
import ensureTestRunnerNestedCount from './rules/ensure-test-runner-nested-count';
|
|
4
5
|
import noInvalidFeatureFlagUsage from './rules/no-invalid-feature-flag-usage';
|
|
@@ -6,16 +7,29 @@ export var rules = {
|
|
|
6
7
|
'ensure-feature-flag-registration': ensureFeatureFlagRegistration,
|
|
7
8
|
'ensure-test-runner-arguments': ensureTestRunnerArguments,
|
|
8
9
|
'ensure-test-runner-nested-count': ensureTestRunnerNestedCount,
|
|
9
|
-
'no-invalid-feature-flag-usage': noInvalidFeatureFlagUsage
|
|
10
|
+
'no-invalid-feature-flag-usage': noInvalidFeatureFlagUsage,
|
|
11
|
+
'no-pre-post-install-scripts': noPreAndPostInstallScripts
|
|
10
12
|
};
|
|
11
13
|
export var configs = {
|
|
12
14
|
recommended: {
|
|
13
15
|
plugins: ['@atlaskit/platform'],
|
|
14
16
|
rules: {
|
|
15
17
|
'@atlaskit/platform/ensure-feature-flag-registration': 'error',
|
|
18
|
+
'@atlaskit/platform/no-pre-post-install-scripts': 'error',
|
|
16
19
|
'@atlaskit/platform/ensure-test-runner-arguments': 'error',
|
|
17
20
|
'@atlaskit/platform/ensure-test-runner-nested-count': 'warn',
|
|
18
21
|
'@atlaskit/platform/no-invalid-feature-flag-usage': 'error'
|
|
19
22
|
}
|
|
20
23
|
}
|
|
24
|
+
};
|
|
25
|
+
export var processors = {
|
|
26
|
+
'package-json-processor': {
|
|
27
|
+
preprocess: function preprocess(source) {
|
|
28
|
+
// augment the json into a js file
|
|
29
|
+
return ["/* eslint-disable quote-props, comma-dangle, quotes, semi, eol-last, @typescript-eslint/semi, no-template-curly-in-string */ module.exports = ".concat(source.trim())];
|
|
30
|
+
},
|
|
31
|
+
postprocess: function postprocess(errors) {
|
|
32
|
+
return errors[0];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
21
35
|
};
|
|
@@ -6,11 +6,12 @@ var rule = {
|
|
|
6
6
|
recommended: false
|
|
7
7
|
},
|
|
8
8
|
type: 'problem',
|
|
9
|
+
fixable: 'code',
|
|
9
10
|
messages: {
|
|
10
11
|
onlyInlineFeatureFlag: 'Only pass in feature flag as string literal, please replace {{identifierName}} with its value.',
|
|
11
12
|
onlyInlineTestFunction: 'Only pass in test functions/cases in an inline manner. Test functions/cases should be passed in directly, instead of as variables. Please replace {{identifierName}} with its own definition.',
|
|
12
|
-
passDownExistingFeatureFlagParam: '
|
|
13
|
-
passDownExistingFeatureFlagArgument: '
|
|
13
|
+
passDownExistingFeatureFlagParam: 'An argument symbolising existing FFs needs to be passed down as param when calling nested test runner. See examples in the package which declares this function.',
|
|
14
|
+
passDownExistingFeatureFlagArgument: 'An argument symbolising existing FFs needs to be passed in as argument when calling nested test runner. See examples in the package which declares this function.',
|
|
14
15
|
passDownExistingFeatureFlagNamesMatch: 'Argument names not matching when passing down existing feature flags. See examples in the package which declares this function.'
|
|
15
16
|
}
|
|
16
17
|
},
|
|
@@ -57,25 +58,35 @@ var rule = {
|
|
|
57
58
|
// Not pass in ff to the function that calls test runner
|
|
58
59
|
if (!node.parent.params[0] || node.parent.params[0].type !== 'Identifier') {
|
|
59
60
|
return context.report({
|
|
60
|
-
node: node,
|
|
61
|
-
messageId: 'passDownExistingFeatureFlagParam'
|
|
61
|
+
node: node.parent,
|
|
62
|
+
messageId: 'passDownExistingFeatureFlagParam',
|
|
63
|
+
fix: function fix(fixer) {
|
|
64
|
+
var parentNodeRange = node.parent.range;
|
|
65
|
+
return [fixer.replaceTextRange([parentNodeRange[0], parentNodeRange[0] + 2], 'ff'), node.arguments[3] ? fixer.replaceText(node.arguments[3], 'ff') : fixer.insertTextAfter(node.arguments[2], ', ff')];
|
|
66
|
+
}
|
|
62
67
|
});
|
|
63
68
|
}
|
|
64
69
|
|
|
65
70
|
// Not pass in ff to test runner as 4th argument
|
|
71
|
+
var paramName = node.parent.params[0].name;
|
|
66
72
|
if (!node.arguments[3] || node.arguments[3].type !== 'Identifier') {
|
|
67
73
|
return context.report({
|
|
68
74
|
node: node,
|
|
69
|
-
messageId: 'passDownExistingFeatureFlagArgument'
|
|
75
|
+
messageId: 'passDownExistingFeatureFlagArgument',
|
|
76
|
+
fix: function fix(fixer) {
|
|
77
|
+
return node.arguments[3] ? fixer.replaceText(node.arguments[3], paramName) : fixer.insertTextAfter(node.arguments[2], ", ".concat(paramName));
|
|
78
|
+
}
|
|
70
79
|
});
|
|
71
80
|
}
|
|
72
81
|
// Pass in the above two, but names don't match
|
|
73
|
-
var paramName = node.parent.params[0].name;
|
|
74
82
|
var arguName = node.arguments[3].name;
|
|
75
83
|
if (paramName !== arguName) {
|
|
76
84
|
return context.report({
|
|
77
|
-
node: node,
|
|
78
|
-
messageId: 'passDownExistingFeatureFlagNamesMatch'
|
|
85
|
+
node: node.parent,
|
|
86
|
+
messageId: 'passDownExistingFeatureFlagNamesMatch',
|
|
87
|
+
fix: function fix(fixer) {
|
|
88
|
+
return fixer.replaceText(node.arguments[3], paramName);
|
|
89
|
+
}
|
|
79
90
|
});
|
|
80
91
|
}
|
|
81
92
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var rule = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: 'problem',
|
|
4
|
+
docs: {
|
|
5
|
+
description: 'This rule disallows public packages to have pre/post install scripts as installations can happen on different environments',
|
|
6
|
+
recommended: false
|
|
7
|
+
},
|
|
8
|
+
hasSuggestions: false,
|
|
9
|
+
messages: {
|
|
10
|
+
prePostInstallScriptsNotAllowed: 'pre/post install scripts not allowed in package.json'
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
create: function create(context) {
|
|
14
|
+
return {
|
|
15
|
+
'ObjectExpression Property[key.value=scripts] Property[key.value=/^(pre|post)install$/]': function ObjectExpressionPropertyKeyValueScriptsPropertyKeyValuePrePostInstall$(node) {
|
|
16
|
+
if (!context.getFilename().endsWith('/package.json')) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
return context.report({
|
|
20
|
+
node: node,
|
|
21
|
+
messageId: 'prePostInstallScriptsNotAllowed'
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
export default rule;
|
package/dist/esm/version.json
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
|
+
import type { Linter } from 'eslint';
|
|
1
2
|
export declare const rules: {
|
|
2
3
|
'ensure-feature-flag-registration': import("eslint").Rule.RuleModule;
|
|
3
4
|
'ensure-test-runner-arguments': import("eslint").Rule.RuleModule;
|
|
4
5
|
'ensure-test-runner-nested-count': import("eslint").Rule.RuleModule;
|
|
5
6
|
'no-invalid-feature-flag-usage': import("eslint").Rule.RuleModule;
|
|
7
|
+
'no-pre-post-install-scripts': import("eslint").Rule.RuleModule;
|
|
6
8
|
};
|
|
7
9
|
export declare const configs: {
|
|
8
10
|
recommended: {
|
|
9
11
|
plugins: string[];
|
|
10
12
|
rules: {
|
|
11
13
|
'@atlaskit/platform/ensure-feature-flag-registration': string;
|
|
14
|
+
'@atlaskit/platform/no-pre-post-install-scripts': string;
|
|
12
15
|
'@atlaskit/platform/ensure-test-runner-arguments': string;
|
|
13
16
|
'@atlaskit/platform/ensure-test-runner-nested-count': string;
|
|
14
17
|
'@atlaskit/platform/no-invalid-feature-flag-usage': string;
|
|
15
18
|
};
|
|
16
19
|
};
|
|
17
20
|
};
|
|
21
|
+
export declare const processors: {
|
|
22
|
+
'package-json-processor': Linter.Processor<string | Linter.ProcessorFile>;
|
|
23
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/eslint-plugin-platform",
|
|
3
3
|
"description": "The essential plugin for use with Atlassian frontend platform tools",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.1.0",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"atlassian": {
|
|
7
7
|
"team": "UIP - Platform Integration Trust (PITa)",
|
package/report.api.md
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
<!--SECTION START: Main Entry Types-->
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
|
+
import type { Linter } from 'eslint';
|
|
18
19
|
import { Rule } from 'eslint';
|
|
19
20
|
|
|
20
21
|
// @public (undocumented)
|
|
@@ -23,6 +24,7 @@ export const configs: {
|
|
|
23
24
|
plugins: string[];
|
|
24
25
|
rules: {
|
|
25
26
|
'@atlaskit/platform/ensure-feature-flag-registration': string;
|
|
27
|
+
'@atlaskit/platform/no-pre-post-install-scripts': string;
|
|
26
28
|
'@atlaskit/platform/ensure-test-runner-arguments': string;
|
|
27
29
|
'@atlaskit/platform/ensure-test-runner-nested-count': string;
|
|
28
30
|
'@atlaskit/platform/no-invalid-feature-flag-usage': string;
|
|
@@ -30,12 +32,18 @@ export const configs: {
|
|
|
30
32
|
};
|
|
31
33
|
};
|
|
32
34
|
|
|
35
|
+
// @public (undocumented)
|
|
36
|
+
export const processors: {
|
|
37
|
+
'package-json-processor': Linter.Processor<Linter.ProcessorFile | string>;
|
|
38
|
+
};
|
|
39
|
+
|
|
33
40
|
// @public (undocumented)
|
|
34
41
|
export const rules: {
|
|
35
42
|
'ensure-feature-flag-registration': Rule.RuleModule;
|
|
36
43
|
'ensure-test-runner-arguments': Rule.RuleModule;
|
|
37
44
|
'ensure-test-runner-nested-count': Rule.RuleModule;
|
|
38
45
|
'no-invalid-feature-flag-usage': Rule.RuleModule;
|
|
46
|
+
'no-pre-post-install-scripts': Rule.RuleModule;
|
|
39
47
|
};
|
|
40
48
|
|
|
41
49
|
// (No @packageDocumentation comment for this package)
|
package/src/index.tsx
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { Linter } from 'eslint';
|
|
1
2
|
import ensureFeatureFlagRegistration from './rules/ensure-feature-flag-registration';
|
|
3
|
+
import noPreAndPostInstallScripts from './rules/no-pre-post-installs';
|
|
2
4
|
import ensureTestRunnerArguments from './rules/ensure-test-runner-arguments';
|
|
3
5
|
import ensureTestRunnerNestedCount from './rules/ensure-test-runner-nested-count';
|
|
4
6
|
import noInvalidFeatureFlagUsage from './rules/no-invalid-feature-flag-usage';
|
|
@@ -8,6 +10,7 @@ export const rules = {
|
|
|
8
10
|
'ensure-test-runner-arguments': ensureTestRunnerArguments,
|
|
9
11
|
'ensure-test-runner-nested-count': ensureTestRunnerNestedCount,
|
|
10
12
|
'no-invalid-feature-flag-usage': noInvalidFeatureFlagUsage,
|
|
13
|
+
'no-pre-post-install-scripts': noPreAndPostInstallScripts,
|
|
11
14
|
};
|
|
12
15
|
|
|
13
16
|
export const configs = {
|
|
@@ -15,9 +18,22 @@ export const configs = {
|
|
|
15
18
|
plugins: ['@atlaskit/platform'],
|
|
16
19
|
rules: {
|
|
17
20
|
'@atlaskit/platform/ensure-feature-flag-registration': 'error',
|
|
21
|
+
'@atlaskit/platform/no-pre-post-install-scripts': 'error',
|
|
18
22
|
'@atlaskit/platform/ensure-test-runner-arguments': 'error',
|
|
19
23
|
'@atlaskit/platform/ensure-test-runner-nested-count': 'warn',
|
|
20
24
|
'@atlaskit/platform/no-invalid-feature-flag-usage': 'error',
|
|
21
25
|
},
|
|
22
26
|
},
|
|
23
27
|
};
|
|
28
|
+
|
|
29
|
+
export const processors = {
|
|
30
|
+
'package-json-processor': {
|
|
31
|
+
preprocess: (source: string) => {
|
|
32
|
+
// augment the json into a js file
|
|
33
|
+
return [
|
|
34
|
+
`/* eslint-disable quote-props, comma-dangle, quotes, semi, eol-last, @typescript-eslint/semi, no-template-curly-in-string */ module.exports = ${source.trim()}`,
|
|
35
|
+
];
|
|
36
|
+
},
|
|
37
|
+
postprocess: (errors) => errors[0],
|
|
38
|
+
} as Linter.Processor,
|
|
39
|
+
};
|
|
@@ -145,6 +145,32 @@ describe('Verify existing ff overrides are passed down if test runner is nested'
|
|
|
145
145
|
),
|
|
146
146
|
);
|
|
147
147
|
`,
|
|
148
|
+
output: `ffTest(
|
|
149
|
+
'uip.sample.color',
|
|
150
|
+
ff =>
|
|
151
|
+
ffTest(
|
|
152
|
+
'uip.sample.backgroundColor',
|
|
153
|
+
() => {
|
|
154
|
+
expect(getByText('SampleComponent')).toHaveStyle('color: red');
|
|
155
|
+
},
|
|
156
|
+
() => {
|
|
157
|
+
expect(getByText('SampleComponent')).toHaveStyle('color: red');
|
|
158
|
+
},
|
|
159
|
+
ff,
|
|
160
|
+
),
|
|
161
|
+
ff =>
|
|
162
|
+
ffTest(
|
|
163
|
+
'uip.sample.backgroundColor',
|
|
164
|
+
() => {
|
|
165
|
+
expect(getByText('SampleComponent')).toHaveStyle('color: blue');
|
|
166
|
+
},
|
|
167
|
+
() => {
|
|
168
|
+
expect(getByText('SampleComponent')).toHaveStyle('color: blue');
|
|
169
|
+
},
|
|
170
|
+
ff,
|
|
171
|
+
),
|
|
172
|
+
);
|
|
173
|
+
`,
|
|
148
174
|
errors: [
|
|
149
175
|
{
|
|
150
176
|
messageId: 'passDownExistingFeatureFlagParam',
|
|
@@ -177,6 +203,31 @@ describe('Verify existing ff overrides are passed down if test runner is nested'
|
|
|
177
203
|
),
|
|
178
204
|
);
|
|
179
205
|
`,
|
|
206
|
+
output: `ffTest(
|
|
207
|
+
'uip.sample.color',
|
|
208
|
+
ff =>
|
|
209
|
+
ffTest(
|
|
210
|
+
'uip.sample.backgroundColor',
|
|
211
|
+
() => {
|
|
212
|
+
expect(getByText('SampleComponent')).toHaveStyle('color: red');
|
|
213
|
+
},
|
|
214
|
+
() => {
|
|
215
|
+
expect(getByText('SampleComponent')).toHaveStyle('color: red');
|
|
216
|
+
}, ff,
|
|
217
|
+
),
|
|
218
|
+
ff =>
|
|
219
|
+
ffTest(
|
|
220
|
+
'uip.sample.backgroundColor',
|
|
221
|
+
() => {
|
|
222
|
+
expect(getByText('SampleComponent')).toHaveStyle('color: blue');
|
|
223
|
+
},
|
|
224
|
+
() => {
|
|
225
|
+
expect(getByText('SampleComponent')).toHaveStyle('color: blue');
|
|
226
|
+
},
|
|
227
|
+
ff,
|
|
228
|
+
),
|
|
229
|
+
);
|
|
230
|
+
`,
|
|
180
231
|
errors: [
|
|
181
232
|
{
|
|
182
233
|
messageId: 'passDownExistingFeatureFlagArgument',
|
|
@@ -210,6 +261,32 @@ describe('Verify existing ff overrides are passed down if test runner is nested'
|
|
|
210
261
|
),
|
|
211
262
|
);
|
|
212
263
|
`,
|
|
264
|
+
output: `ffTest(
|
|
265
|
+
'uip.sample.color',
|
|
266
|
+
ff =>
|
|
267
|
+
ffTest(
|
|
268
|
+
'uip.sample.backgroundColor',
|
|
269
|
+
() => {
|
|
270
|
+
expect(getByText('SampleComponent')).toHaveStyle('color: red');
|
|
271
|
+
},
|
|
272
|
+
() => {
|
|
273
|
+
expect(getByText('SampleComponent')).toHaveStyle('color: red');
|
|
274
|
+
},
|
|
275
|
+
ff,
|
|
276
|
+
),
|
|
277
|
+
ff =>
|
|
278
|
+
ffTest(
|
|
279
|
+
'uip.sample.backgroundColor',
|
|
280
|
+
() => {
|
|
281
|
+
expect(getByText('SampleComponent')).toHaveStyle('color: blue');
|
|
282
|
+
},
|
|
283
|
+
() => {
|
|
284
|
+
expect(getByText('SampleComponent')).toHaveStyle('color: blue');
|
|
285
|
+
},
|
|
286
|
+
ff,
|
|
287
|
+
),
|
|
288
|
+
);
|
|
289
|
+
`,
|
|
213
290
|
errors: [
|
|
214
291
|
{
|
|
215
292
|
messageId: 'passDownExistingFeatureFlagNamesMatch',
|
|
@@ -8,15 +8,16 @@ const rule: Rule.RuleModule = {
|
|
|
8
8
|
recommended: false,
|
|
9
9
|
},
|
|
10
10
|
type: 'problem',
|
|
11
|
+
fixable: 'code',
|
|
11
12
|
messages: {
|
|
12
13
|
onlyInlineFeatureFlag:
|
|
13
14
|
'Only pass in feature flag as string literal, please replace {{identifierName}} with its value.',
|
|
14
15
|
onlyInlineTestFunction:
|
|
15
16
|
'Only pass in test functions/cases in an inline manner. Test functions/cases should be passed in directly, instead of as variables. Please replace {{identifierName}} with its own definition.',
|
|
16
17
|
passDownExistingFeatureFlagParam:
|
|
17
|
-
'
|
|
18
|
+
'An argument symbolising existing FFs needs to be passed down as param when calling nested test runner. See examples in the package which declares this function.',
|
|
18
19
|
passDownExistingFeatureFlagArgument:
|
|
19
|
-
'
|
|
20
|
+
'An argument symbolising existing FFs needs to be passed in as argument when calling nested test runner. See examples in the package which declares this function.',
|
|
20
21
|
passDownExistingFeatureFlagNamesMatch:
|
|
21
22
|
'Argument names not matching when passing down existing feature flags. See examples in the package which declares this function.',
|
|
22
23
|
},
|
|
@@ -78,25 +79,48 @@ const rule: Rule.RuleModule = {
|
|
|
78
79
|
node.parent.params[0].type !== 'Identifier'
|
|
79
80
|
) {
|
|
80
81
|
return context.report({
|
|
81
|
-
node,
|
|
82
|
+
node: node.parent,
|
|
82
83
|
messageId: 'passDownExistingFeatureFlagParam',
|
|
84
|
+
fix: function (fixer) {
|
|
85
|
+
const parentNodeRange = node.parent.range as [number, number];
|
|
86
|
+
return [
|
|
87
|
+
fixer.replaceTextRange(
|
|
88
|
+
[parentNodeRange[0], parentNodeRange[0] + 2],
|
|
89
|
+
'ff',
|
|
90
|
+
),
|
|
91
|
+
node.arguments[3]
|
|
92
|
+
? fixer.replaceText(node.arguments[3], 'ff')
|
|
93
|
+
: fixer.insertTextAfter(node.arguments[2], ', ff'),
|
|
94
|
+
];
|
|
95
|
+
},
|
|
83
96
|
});
|
|
84
97
|
}
|
|
85
98
|
|
|
86
99
|
// Not pass in ff to test runner as 4th argument
|
|
100
|
+
const paramName = node.parent.params[0].name;
|
|
87
101
|
if (!node.arguments[3] || node.arguments[3].type !== 'Identifier') {
|
|
88
102
|
return context.report({
|
|
89
103
|
node,
|
|
90
104
|
messageId: 'passDownExistingFeatureFlagArgument',
|
|
105
|
+
fix: function (fixer) {
|
|
106
|
+
return node.arguments[3]
|
|
107
|
+
? fixer.replaceText(node.arguments[3], paramName)
|
|
108
|
+
: fixer.insertTextAfter(
|
|
109
|
+
node.arguments[2],
|
|
110
|
+
`, ${paramName}`,
|
|
111
|
+
);
|
|
112
|
+
},
|
|
91
113
|
});
|
|
92
114
|
}
|
|
93
115
|
// Pass in the above two, but names don't match
|
|
94
|
-
const paramName = node.parent.params[0].name;
|
|
95
116
|
const arguName = node.arguments[3].name;
|
|
96
117
|
if (paramName !== arguName) {
|
|
97
118
|
return context.report({
|
|
98
|
-
node,
|
|
119
|
+
node: node.parent,
|
|
99
120
|
messageId: 'passDownExistingFeatureFlagNamesMatch',
|
|
121
|
+
fix: function (fixer) {
|
|
122
|
+
return fixer.replaceText(node.arguments[3], paramName);
|
|
123
|
+
},
|
|
100
124
|
});
|
|
101
125
|
}
|
|
102
126
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { tester } from '../../../../__tests__/utils/_tester';
|
|
2
|
+
import rule from '../../index';
|
|
3
|
+
|
|
4
|
+
describe('test no-pre-post-installs rule', () => {
|
|
5
|
+
tester.run('no-pre-post-installs', rule, {
|
|
6
|
+
valid: [
|
|
7
|
+
{
|
|
8
|
+
code: `const foo = { "scripts": { "preinstall": 1, "postinstall": 2 }}`,
|
|
9
|
+
filename: 'hello/foo.ts',
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
code: `const foo = { "scripts": { "preinstall": 1, "postinstall": 2 }}`,
|
|
13
|
+
filename: 'foo/dummy.json',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
code: `const foo = { "scripts": { "bar": 1, "dummy": 'echo 1' }}`,
|
|
17
|
+
filename: 'foo/package.json',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
code: `module.exports = { "scripts": { "fakePreinstall": 1 }};`,
|
|
21
|
+
filename: 'bar/package.json',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
code: `module.exports = { "scripts": { "fakePostinstall": 1 }};`,
|
|
25
|
+
filename: 'bar/package.json',
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
invalid: [
|
|
29
|
+
{
|
|
30
|
+
code: `module.exports = { "scripts": { "preinstall": 1 }};`,
|
|
31
|
+
filename: 'bar/package.json',
|
|
32
|
+
errors: [{ messageId: 'prePostInstallScriptsNotAllowed' }],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
code: `const foo = { "scripts": { "postinstall": 1 }}`,
|
|
36
|
+
filename: 'baz/package.json',
|
|
37
|
+
errors: [{ messageId: 'prePostInstallScriptsNotAllowed' }],
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
|
|
3
|
+
const rule: Rule.RuleModule = {
|
|
4
|
+
meta: {
|
|
5
|
+
type: 'problem',
|
|
6
|
+
docs: {
|
|
7
|
+
description:
|
|
8
|
+
'This rule disallows public packages to have pre/post install scripts as installations can happen on different environments',
|
|
9
|
+
recommended: false,
|
|
10
|
+
},
|
|
11
|
+
hasSuggestions: false,
|
|
12
|
+
messages: {
|
|
13
|
+
prePostInstallScriptsNotAllowed:
|
|
14
|
+
'pre/post install scripts not allowed in package.json',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
create(context) {
|
|
18
|
+
return {
|
|
19
|
+
'ObjectExpression Property[key.value=scripts] Property[key.value=/^(pre|post)install$/]':
|
|
20
|
+
(node: Rule.Node) => {
|
|
21
|
+
if (!context.getFilename().endsWith('/package.json')) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return context.report({
|
|
26
|
+
node,
|
|
27
|
+
messageId: 'prePostInstallScriptsNotAllowed',
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default rule;
|
package/tmp/api-report-tmp.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
```ts
|
|
6
6
|
|
|
7
|
+
import type { Linter } from 'eslint';
|
|
7
8
|
import { Rule } from 'eslint';
|
|
8
9
|
|
|
9
10
|
// @public (undocumented)
|
|
@@ -12,6 +13,7 @@ export const configs: {
|
|
|
12
13
|
plugins: string[];
|
|
13
14
|
rules: {
|
|
14
15
|
'@atlaskit/platform/ensure-feature-flag-registration': string;
|
|
16
|
+
'@atlaskit/platform/no-pre-post-install-scripts': string;
|
|
15
17
|
'@atlaskit/platform/ensure-test-runner-arguments': string;
|
|
16
18
|
'@atlaskit/platform/ensure-test-runner-nested-count': string;
|
|
17
19
|
'@atlaskit/platform/no-invalid-feature-flag-usage': string;
|
|
@@ -19,12 +21,18 @@ export const configs: {
|
|
|
19
21
|
};
|
|
20
22
|
};
|
|
21
23
|
|
|
24
|
+
// @public (undocumented)
|
|
25
|
+
export const processors: {
|
|
26
|
+
'package-json-processor': Linter.Processor<Linter.ProcessorFile | string>;
|
|
27
|
+
};
|
|
28
|
+
|
|
22
29
|
// @public (undocumented)
|
|
23
30
|
export const rules: {
|
|
24
31
|
'ensure-feature-flag-registration': Rule.RuleModule;
|
|
25
32
|
'ensure-test-runner-arguments': Rule.RuleModule;
|
|
26
33
|
'ensure-test-runner-nested-count': Rule.RuleModule;
|
|
27
34
|
'no-invalid-feature-flag-usage': Rule.RuleModule;
|
|
35
|
+
'no-pre-post-install-scripts': Rule.RuleModule;
|
|
28
36
|
};
|
|
29
37
|
|
|
30
38
|
// (No @packageDocumentation comment for this package)
|