@atlaskit/eslint-plugin-platform 2.5.0 → 2.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/afm-cc/tsconfig.json +1 -1
  3. package/dist/cjs/index.js +40 -3
  4. package/dist/cjs/rules/ensure-native-and-af-exports-synced/index.js +3 -0
  5. package/dist/cjs/rules/ensure-valid-platform-yarn-protocol-usage/index.js +1 -1
  6. package/dist/cjs/rules/feature-gating/no-preconditioning/index.js +1 -1
  7. package/dist/cjs/rules/no-direct-document-usage/index.js +103 -0
  8. package/dist/cjs/rules/no-sparse-checkout/index.js +43 -0
  9. package/dist/cjs/rules/util/file-exclusions.js +45 -0
  10. package/dist/es2019/index.js +40 -3
  11. package/dist/es2019/rules/ensure-native-and-af-exports-synced/index.js +3 -0
  12. package/dist/es2019/rules/ensure-valid-platform-yarn-protocol-usage/index.js +1 -1
  13. package/dist/es2019/rules/feature-gating/no-preconditioning/index.js +1 -1
  14. package/dist/es2019/rules/no-direct-document-usage/index.js +95 -0
  15. package/dist/es2019/rules/no-sparse-checkout/index.js +35 -0
  16. package/dist/es2019/rules/util/file-exclusions.js +37 -0
  17. package/dist/esm/index.js +40 -3
  18. package/dist/esm/rules/ensure-native-and-af-exports-synced/index.js +3 -0
  19. package/dist/esm/rules/ensure-valid-platform-yarn-protocol-usage/index.js +1 -1
  20. package/dist/esm/rules/feature-gating/no-preconditioning/index.js +1 -1
  21. package/dist/esm/rules/no-direct-document-usage/index.js +97 -0
  22. package/dist/esm/rules/no-sparse-checkout/index.js +37 -0
  23. package/dist/esm/rules/util/file-exclusions.js +39 -0
  24. package/dist/types/index.d.ts +12 -0
  25. package/dist/types/rules/no-direct-document-usage/index.d.ts +3 -0
  26. package/dist/types/rules/no-sparse-checkout/index.d.ts +3 -0
  27. package/dist/types/rules/util/file-exclusions.d.ts +13 -0
  28. package/dist/types-ts4.5/index.d.ts +12 -0
  29. package/dist/types-ts4.5/rules/no-direct-document-usage/index.d.ts +3 -0
  30. package/dist/types-ts4.5/rules/no-sparse-checkout/index.d.ts +3 -0
  31. package/dist/types-ts4.5/rules/util/file-exclusions.d.ts +13 -0
  32. package/package.json +10 -1
  33. package/src/index.tsx +44 -2
  34. package/src/rules/ensure-native-and-af-exports-synced/index.tsx +3 -0
  35. package/src/rules/ensure-valid-bin-values/__tests__/unit/rule.test.ts +3 -2
  36. package/src/rules/ensure-valid-platform-yarn-protocol-usage/index.ts +1 -1
  37. package/src/rules/feature-gating/no-preconditioning/index.tsx +1 -1
  38. package/src/rules/no-direct-document-usage/index.tsx +109 -0
  39. package/src/rules/no-sparse-checkout/__tests__/unit/rule.test.tsx +48 -0
  40. package/src/rules/no-sparse-checkout/index.tsx +54 -0
  41. package/src/rules/util/file-exclusions.ts +39 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @atlaskit/eslint-plugin-platform
2
2
 
3
+ ## 2.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#168806](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/168806)
8
+ [`e4f94f422b9f1`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e4f94f422b9f1) -
9
+ New linting rule to prevent direct "document" usage. This prevents failed tests when document is
10
+ not defined in the testing environment
11
+
3
12
  ## 2.5.0
4
13
 
5
14
  ### Minor Changes
@@ -3,7 +3,7 @@
3
3
  "compilerOptions": {
4
4
  "target": "es5",
5
5
  "composite": true,
6
- "outDir": "../dist",
6
+ "outDir": "../../../../../confluence/tsDist/@atlaskit__eslint-plugin-platform",
7
7
  "rootDir": "../"
8
8
  },
9
9
  "include": [
package/dist/cjs/index.js CHANGED
@@ -34,8 +34,28 @@ var _useEntrypointsInExamples = _interopRequireDefault(require("./rules/use-entr
34
34
  var _useRecommendedUtils = _interopRequireDefault(require("./rules/feature-gating/use-recommended-utils"));
35
35
  var _expandBackgroundShorthand = _interopRequireDefault(require("./rules/compiled/expand-background-shorthand"));
36
36
  var _expandSpacingShorthand = _interopRequireDefault(require("./rules/compiled/expand-spacing-shorthand"));
37
+ var _noSparseCheckout = _interopRequireDefault(require("./rules/no-sparse-checkout"));
38
+ var _noDirectDocumentUsage = _interopRequireDefault(require("./rules/no-direct-document-usage"));
39
+ var _nodePath = require("node:path");
40
+ var _nodeFs = require("node:fs");
37
41
  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; }
38
42
  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
43
+ var jiraRoot;
44
+ try {
45
+ var findUp = require('find-up');
46
+ findUp.sync(function (dir) {
47
+ var productsJsonPath = (0, _nodePath.join)(dir, 'products.json');
48
+ if (findUp.sync.exists(productsJsonPath)) {
49
+ var productJson = JSON.parse((0, _nodeFs.readFileSync)(productsJsonPath, 'utf-8'));
50
+ if (productJson.Jira) {
51
+ jiraRoot = (0, _nodePath.normalize)((0, _nodePath.join)(dir, productJson.Jira.path));
52
+ return findUp.stop;
53
+ }
54
+ }
55
+ });
56
+ } catch (_unused) {
57
+ // we aren't running inside of AFM, so we can ignore this.
58
+ }
39
59
  var packageJson = require('@atlaskit/eslint-plugin-platform/package.json');
40
60
  var rules = exports.rules = {
41
61
  'ensure-feature-flag-registration': _ensureFeatureFlagRegistration.default,
@@ -64,7 +84,9 @@ var rules = exports.rules = {
64
84
  'prefer-fg': _preferFg.default,
65
85
  'no-alias': _noAlias.default,
66
86
  'use-entrypoints-in-examples': _useEntrypointsInExamples.default,
67
- 'use-recommended-utils': _useRecommendedUtils.default
87
+ 'use-recommended-utils': _useRecommendedUtils.default,
88
+ 'no-sparse-checkout': _noSparseCheckout.default,
89
+ 'no-direct-document-usage': _noDirectDocumentUsage.default
68
90
  };
69
91
  var commonConfig = {
70
92
  '@atlaskit/platform/ensure-test-runner-arguments': 'error',
@@ -73,6 +95,7 @@ var commonConfig = {
73
95
  '@atlaskit/platform/no-invalid-storybook-decorator-usage': 'error',
74
96
  '@atlaskit/platform/ensure-atlassian-team': 'error',
75
97
  '@atlaskit/platform/no-module-level-eval-nav4': 'error',
98
+ '@atlaskit/platform/no-direct-document-usage': 'warn',
76
99
  // Compiled: rules that are not included via `@compiled/recommended
77
100
  '@atlaskit/platform/expand-border-shorthand': 'error',
78
101
  '@atlaskit/platform/expand-background-shorthand': 'error',
@@ -101,6 +124,7 @@ var recommendedRules = _objectSpread(_objectSpread({}, commonConfig), {}, {
101
124
  var jiraRules = commonConfig;
102
125
  var jsonPrefix = '/* eslint-disable quote-props, comma-dangle, quotes, semi, eol-last, @typescript-eslint/semi, no-template-curly-in-string */ module.exports = ';
103
126
  var jsonPrefixForFlatConfig = '/* eslint-disable quote-props, comma-dangle, quotes, semi, eol-last, no-template-curly-in-string */ module.exports = ';
127
+ var jsonPrefixForJira = 'module.exports = ';
104
128
  var name = packageJson.name,
105
129
  version = packageJson.version;
106
130
  var plugin = exports.plugin = {
@@ -147,7 +171,14 @@ var plugin = exports.plugin = {
147
171
  },
148
172
  processors: {
149
173
  'package-json-processor': {
150
- preprocess: function preprocess(source) {
174
+ preprocess: function preprocess(source, filename) {
175
+ // we only need to check for jiraRoot because it uses a different
176
+ // ESLint version and produces fake errors due to how this processor handles JSON
177
+ if (jiraRoot && filename.startsWith(jiraRoot)) {
178
+ // augment the json into a js file
179
+ return [jsonPrefixForJira + source.trim()];
180
+ }
181
+
151
182
  // augment the json into a js file
152
183
  return [jsonPrefix + source.trim()];
153
184
  },
@@ -170,7 +201,13 @@ var plugin = exports.plugin = {
170
201
  // This processor is used for ESLint FlatConfig,
171
202
  // once we roll out FlatConfig, we can remove the above processor
172
203
  'package-json-processor-for-flat-config': {
173
- preprocess: function preprocess(source) {
204
+ // we only need to check for jiraRoot because it uses a different
205
+ // ESLint version and produces fake errors due to how this processor handles JSON
206
+ preprocess: function preprocess(source, filename) {
207
+ if (jiraRoot && filename.startsWith(jiraRoot)) {
208
+ // augment the json into a js file
209
+ return [jsonPrefixForJira + source.trim()];
210
+ }
174
211
  // augment the json into a js file
175
212
  return [jsonPrefixForFlatConfig + source.trim()];
176
213
  },
@@ -13,6 +13,9 @@ var _registrationUtils = require("../util/registration-utils");
13
13
  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; }
14
14
  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; }
15
15
  var exportsValidationExceptions = {
16
+ '@af/yarn-workspace': {
17
+ ignoredAfExportKeys: ['./lock-parser']
18
+ },
16
19
  '@atlaskit/tokens': {
17
20
  ignoredAfExportKeys: ['./babel-plugin']
18
21
  },
@@ -53,7 +53,7 @@ var rule = {
53
53
  },
54
54
  hasSuggestions: false,
55
55
  messages: {
56
- invalidWorkspaceProtocolUsage: "The 'workspace:^' or 'workspace:~' protocol is Used. To resolve this error, please use the 'workspace:*' protocol instead.",
56
+ invalidWorkspaceProtocolUsage: "The 'workspace:^'protocol is Used. To resolve this error, please use the 'workspace:*' protocol instead.",
57
57
  invalidRootProtocolUsage: "The 'root:' protocol is not allowed in platform packages. To resolve this error, replace the 'root:' protocol with specific package versions (e.g. '^1.0.0')."
58
58
  }
59
59
  },
@@ -55,7 +55,7 @@ var rule = {
55
55
  url: 'https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo/browse/platform/packages/platform/eslint-plugin/src/rules/no-preconditioning/README.md'
56
56
  },
57
57
  messages: {
58
- useConfig: 'Do not precondition gates or experiments with another gate. Configure this in Statsig instead to reduce unnecessary code and simplify cleanup.',
58
+ useConfig: 'Do not precondition gates or experiments with another gate. Configure this in Statsig instead to reduce unnecessary code, simplify cleanup and to ensure accurate exposures in Statsig.',
59
59
  incorrectExposure: 'Evaluate gates or experiments at the end of your logical expression to ensure exposure is tracked correctly.'
60
60
  }
61
61
  },
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _fileExclusions = require("../util/file-exclusions");
8
+ var rule = {
9
+ meta: {
10
+ type: 'problem',
11
+ docs: {
12
+ description: 'Enforce using getDocument from @atlaskit/browser-apis instead of direct document usage',
13
+ recommended: true
14
+ },
15
+ messages: {
16
+ useGetDocument: 'Use getDocument from @atlaskit/browser-apis instead of direct document usage'
17
+ },
18
+ schema: []
19
+ },
20
+ create: function create(context) {
21
+ var hasGetDocumentImport = false;
22
+ var filename = context.filename;
23
+
24
+ // Skip test files
25
+ var skipResult = (0, _fileExclusions.skipForTestFiles)(context);
26
+ if (skipResult) {
27
+ return skipResult;
28
+ }
29
+
30
+ // Skip example files
31
+ var skipResult2 = (0, _fileExclusions.skipForExampleFiles)(context);
32
+ if (skipResult2) {
33
+ return skipResult2;
34
+ }
35
+
36
+ // Skip the getDocument.ts file itself
37
+ if (filename.endsWith('getDocument.ts')) {
38
+ return {};
39
+ }
40
+ return {
41
+ ImportDeclaration: function ImportDeclaration(node) {
42
+ if (node.source.value === '@atlaskit/browser-apis' && node.specifiers.some(function (specifier) {
43
+ return specifier.type === 'ImportSpecifier' && specifier.imported.name === 'getDocument';
44
+ })) {
45
+ hasGetDocumentImport = true;
46
+ }
47
+ },
48
+ Identifier: function Identifier(node) {
49
+ if (node.name === 'document' && !hasGetDocumentImport) {
50
+ var parent = node.parent;
51
+
52
+ // Skip if 'document' is used as a property key in an object literal
53
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Property' && parent.key === node) {
54
+ return;
55
+ }
56
+
57
+ // Skip if 'document' is used as a shorthand property value
58
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Property' && parent.value === node && parent.shorthand) {
59
+ return;
60
+ }
61
+
62
+ // Skip if 'document' is used as a property being accessed in a member expression
63
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'MemberExpression' && parent.property === node && !parent.computed) {
64
+ return;
65
+ }
66
+
67
+ // Skip if 'document' is being declared as a variable
68
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'VariableDeclarator' && parent.id === node) {
69
+ return;
70
+ }
71
+
72
+ // Skip if 'document' is a function name
73
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'FunctionDeclaration' && 'id' in parent && parent.id === node) {
74
+ return;
75
+ }
76
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'FunctionExpression' && 'id' in parent && parent.id === node) {
77
+ return;
78
+ }
79
+
80
+ // Skip if 'document' is a method name in a class or object
81
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'MethodDefinition' && parent.key === node) {
82
+ return;
83
+ }
84
+
85
+ // Skip if 'document' is being assigned to (shadowing the global)
86
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'AssignmentExpression' && parent.left === node) {
87
+ return;
88
+ }
89
+
90
+ // Skip if 'document' is in a destructuring pattern (could be destructuring from an object)
91
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ObjectPattern' || (parent === null || parent === void 0 ? void 0 : parent.type) === 'ArrayPattern') {
92
+ return;
93
+ }
94
+ context.report({
95
+ node: node,
96
+ messageId: 'useGetDocument'
97
+ });
98
+ }
99
+ }
100
+ };
101
+ }
102
+ };
103
+ var _default = exports.default = rule;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ // We will be removing sparse checkout from pipelines in CI completely due to the load it causes on BBC.
8
+ // We will be incrementally removing sparse-checkout from the files below as it is probably unnecessasry.
9
+ // If you must add an exception below, please go through the chopper process before doing so
10
+ var sparseCheckoutExceptions = ['bitbucket-pipelines/pipelines/custom/run-issue-automat.ts', 'bitbucket-pipelines/pipelines/custom/marketplace/utils.ts', 'bitbucket-pipelines/pipelines/custom/confluence/utils/index.ts', 'bitbucket-pipelines/pipelines/custom/afm-tools/upload-afm-dependency-graph-cache.ts', 'bitbucket-pipelines/pipelines/custom/afm-tools/default-afm-tools.ts', 'bitbucket-pipelines/pipelines/custom/marketplace/utils.ts', 'bitbucket-pipelines/pipelines/custom/afm-git-hooks.ts', 'bitbucket-pipelines/pipelines/custom/update-codeowners-and-teams-gen.ts', 'bitbucket-pipelines/pipelines/custom/run-issue-automat.ts'];
11
+ var rule = {
12
+ meta: {
13
+ docs: {
14
+ recommended: false
15
+ },
16
+ type: 'problem',
17
+ messages: {
18
+ noSparseCheckout: 'Sparse checkout is not allowed in pipeline configurations. Use git-alternates instead by setting sparseCheckout to false or add this file to exceptions.'
19
+ }
20
+ },
21
+ create: function create(context) {
22
+ var fileName = context.filename;
23
+ if (sparseCheckoutExceptions.some(function (exception) {
24
+ return fileName.endsWith(exception);
25
+ })) {
26
+ return {};
27
+ }
28
+ return {
29
+ // Look for calls to afmClone or objects that match AFMCloneConfig type
30
+ 'CallExpression[callee.object.name=alias][callee.property.name=afmClone] ObjectExpression Property': function CallExpressionCalleeObjectNameAliasCalleePropertyNameAfmClone_ObjectExpression_Property(node) {
31
+ if (node.key.type === 'Identifier' && node.key.name === 'sparseCheckout') {
32
+ if (node.value.type === 'Literal' && node.value.value === true) {
33
+ context.report({
34
+ node: node,
35
+ messageId: 'noSparseCheckout'
36
+ });
37
+ }
38
+ }
39
+ }
40
+ };
41
+ }
42
+ };
43
+ var _default = exports.default = rule;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.skipForTestFiles = exports.skipForExampleFiles = void 0;
7
+ /**
8
+ * Common patterns for test files that should be excluded from rules
9
+ */
10
+ var TEST_FILE_PATTERNS = ['__tests__', 'test', 'spec'];
11
+
12
+ /**
13
+ * Checks if a file should be excluded from rules based on test file patterns
14
+ * @param filename The filename to check
15
+ * @returns true if the file should be excluded, false otherwise
16
+ */
17
+ var isTestFile = function isTestFile(filename) {
18
+ return TEST_FILE_PATTERNS.some(function (pattern) {
19
+ return filename.includes(pattern);
20
+ });
21
+ };
22
+
23
+ /**
24
+ * Helper function to skip rules for test files
25
+ * @param context The ESLint rule context
26
+ * @returns An empty RuleListener if the file is a test file, undefined otherwise
27
+ */
28
+ var skipForTestFiles = exports.skipForTestFiles = function skipForTestFiles(context) {
29
+ if (isTestFile(context.filename)) {
30
+ return {};
31
+ }
32
+ return undefined;
33
+ };
34
+
35
+ /**
36
+ * Helper function to skip rules for example files
37
+ * @param context The ESLint rule context
38
+ * @returns An empty RuleListener if the file is an example file, undefined otherwise
39
+ */
40
+ var skipForExampleFiles = exports.skipForExampleFiles = function skipForExampleFiles(context) {
41
+ if (context.filename.includes('example')) {
42
+ return {};
43
+ }
44
+ return undefined;
45
+ };
@@ -27,6 +27,26 @@ import useEntrypointsInExamples from './rules/use-entrypoints-in-examples';
27
27
  import useRecommendedUtils from './rules/feature-gating/use-recommended-utils';
28
28
  import expandBackgroundShorthand from './rules/compiled/expand-background-shorthand';
29
29
  import expandSpacingShorthand from './rules/compiled/expand-spacing-shorthand';
30
+ import noSparseCheckout from './rules/no-sparse-checkout';
31
+ import noDirectDocumentUsage from './rules/no-direct-document-usage';
32
+ import { join, normalize } from 'node:path';
33
+ import { readFileSync } from 'node:fs';
34
+ let jiraRoot;
35
+ try {
36
+ const findUp = require('find-up');
37
+ findUp.sync(dir => {
38
+ const productsJsonPath = join(dir, 'products.json');
39
+ if (findUp.sync.exists(productsJsonPath)) {
40
+ const productJson = JSON.parse(readFileSync(productsJsonPath, 'utf-8'));
41
+ if (productJson.Jira) {
42
+ jiraRoot = normalize(join(dir, productJson.Jira.path));
43
+ return findUp.stop;
44
+ }
45
+ }
46
+ });
47
+ } catch {
48
+ // we aren't running inside of AFM, so we can ignore this.
49
+ }
30
50
  const packageJson = require('@atlaskit/eslint-plugin-platform/package.json');
31
51
  const rules = {
32
52
  'ensure-feature-flag-registration': ensureFeatureFlagRegistration,
@@ -55,7 +75,9 @@ const rules = {
55
75
  'prefer-fg': preferFG,
56
76
  'no-alias': noAlias,
57
77
  'use-entrypoints-in-examples': useEntrypointsInExamples,
58
- 'use-recommended-utils': useRecommendedUtils
78
+ 'use-recommended-utils': useRecommendedUtils,
79
+ 'no-sparse-checkout': noSparseCheckout,
80
+ 'no-direct-document-usage': noDirectDocumentUsage
59
81
  };
60
82
  const commonConfig = {
61
83
  '@atlaskit/platform/ensure-test-runner-arguments': 'error',
@@ -64,6 +86,7 @@ const commonConfig = {
64
86
  '@atlaskit/platform/no-invalid-storybook-decorator-usage': 'error',
65
87
  '@atlaskit/platform/ensure-atlassian-team': 'error',
66
88
  '@atlaskit/platform/no-module-level-eval-nav4': 'error',
89
+ '@atlaskit/platform/no-direct-document-usage': 'warn',
67
90
  // Compiled: rules that are not included via `@compiled/recommended
68
91
  '@atlaskit/platform/expand-border-shorthand': 'error',
69
92
  '@atlaskit/platform/expand-background-shorthand': 'error',
@@ -93,6 +116,7 @@ const recommendedRules = {
93
116
  const jiraRules = commonConfig;
94
117
  const jsonPrefix = '/* eslint-disable quote-props, comma-dangle, quotes, semi, eol-last, @typescript-eslint/semi, no-template-curly-in-string */ module.exports = ';
95
118
  const jsonPrefixForFlatConfig = '/* eslint-disable quote-props, comma-dangle, quotes, semi, eol-last, no-template-curly-in-string */ module.exports = ';
119
+ const jsonPrefixForJira = 'module.exports = ';
96
120
  const {
97
121
  name,
98
122
  version
@@ -141,7 +165,14 @@ const plugin = {
141
165
  },
142
166
  processors: {
143
167
  'package-json-processor': {
144
- preprocess: source => {
168
+ preprocess: (source, filename) => {
169
+ // we only need to check for jiraRoot because it uses a different
170
+ // ESLint version and produces fake errors due to how this processor handles JSON
171
+ if (jiraRoot && filename.startsWith(jiraRoot)) {
172
+ // augment the json into a js file
173
+ return [jsonPrefixForJira + source.trim()];
174
+ }
175
+
145
176
  // augment the json into a js file
146
177
  return [jsonPrefix + source.trim()];
147
178
  },
@@ -168,7 +199,13 @@ const plugin = {
168
199
  // This processor is used for ESLint FlatConfig,
169
200
  // once we roll out FlatConfig, we can remove the above processor
170
201
  'package-json-processor-for-flat-config': {
171
- preprocess: source => {
202
+ // we only need to check for jiraRoot because it uses a different
203
+ // ESLint version and produces fake errors due to how this processor handles JSON
204
+ preprocess: (source, filename) => {
205
+ if (jiraRoot && filename.startsWith(jiraRoot)) {
206
+ // augment the json into a js file
207
+ return [jsonPrefixForJira + source.trim()];
208
+ }
172
209
  // augment the json into a js file
173
210
  return [jsonPrefixForFlatConfig + source.trim()];
174
211
  },
@@ -1,6 +1,9 @@
1
1
  import path from 'path';
2
2
  import { getMetadataForFilename } from '../util/registration-utils';
3
3
  const exportsValidationExceptions = {
4
+ '@af/yarn-workspace': {
5
+ ignoredAfExportKeys: ['./lock-parser']
6
+ },
4
7
  '@atlaskit/tokens': {
5
8
  ignoredAfExportKeys: ['./babel-plugin']
6
9
  },
@@ -36,7 +36,7 @@ const rule = {
36
36
  },
37
37
  hasSuggestions: false,
38
38
  messages: {
39
- invalidWorkspaceProtocolUsage: `The 'workspace:^' or 'workspace:~' protocol is Used. To resolve this error, please use the 'workspace:*' protocol instead.`,
39
+ invalidWorkspaceProtocolUsage: `The 'workspace:^'protocol is Used. To resolve this error, please use the 'workspace:*' protocol instead.`,
40
40
  invalidRootProtocolUsage: `The 'root:' protocol is not allowed in platform packages. To resolve this error, replace the 'root:' protocol with specific package versions (e.g. '^1.0.0').`
41
41
  }
42
42
  },
@@ -50,7 +50,7 @@ const rule = {
50
50
  url: 'https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo/browse/platform/packages/platform/eslint-plugin/src/rules/no-preconditioning/README.md'
51
51
  },
52
52
  messages: {
53
- useConfig: 'Do not precondition gates or experiments with another gate. Configure this in Statsig instead to reduce unnecessary code and simplify cleanup.',
53
+ useConfig: 'Do not precondition gates or experiments with another gate. Configure this in Statsig instead to reduce unnecessary code, simplify cleanup and to ensure accurate exposures in Statsig.',
54
54
  incorrectExposure: 'Evaluate gates or experiments at the end of your logical expression to ensure exposure is tracked correctly.'
55
55
  }
56
56
  },
@@ -0,0 +1,95 @@
1
+ import { skipForExampleFiles, skipForTestFiles } from '../util/file-exclusions';
2
+ const rule = {
3
+ meta: {
4
+ type: 'problem',
5
+ docs: {
6
+ description: 'Enforce using getDocument from @atlaskit/browser-apis instead of direct document usage',
7
+ recommended: true
8
+ },
9
+ messages: {
10
+ useGetDocument: 'Use getDocument from @atlaskit/browser-apis instead of direct document usage'
11
+ },
12
+ schema: []
13
+ },
14
+ create(context) {
15
+ let hasGetDocumentImport = false;
16
+ const filename = context.filename;
17
+
18
+ // Skip test files
19
+ const skipResult = skipForTestFiles(context);
20
+ if (skipResult) {
21
+ return skipResult;
22
+ }
23
+
24
+ // Skip example files
25
+ const skipResult2 = skipForExampleFiles(context);
26
+ if (skipResult2) {
27
+ return skipResult2;
28
+ }
29
+
30
+ // Skip the getDocument.ts file itself
31
+ if (filename.endsWith('getDocument.ts')) {
32
+ return {};
33
+ }
34
+ return {
35
+ ImportDeclaration(node) {
36
+ if (node.source.value === '@atlaskit/browser-apis' && node.specifiers.some(specifier => specifier.type === 'ImportSpecifier' && specifier.imported.name === 'getDocument')) {
37
+ hasGetDocumentImport = true;
38
+ }
39
+ },
40
+ Identifier(node) {
41
+ if (node.name === 'document' && !hasGetDocumentImport) {
42
+ const parent = node.parent;
43
+
44
+ // Skip if 'document' is used as a property key in an object literal
45
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Property' && parent.key === node) {
46
+ return;
47
+ }
48
+
49
+ // Skip if 'document' is used as a shorthand property value
50
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Property' && parent.value === node && parent.shorthand) {
51
+ return;
52
+ }
53
+
54
+ // Skip if 'document' is used as a property being accessed in a member expression
55
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'MemberExpression' && parent.property === node && !parent.computed) {
56
+ return;
57
+ }
58
+
59
+ // Skip if 'document' is being declared as a variable
60
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'VariableDeclarator' && parent.id === node) {
61
+ return;
62
+ }
63
+
64
+ // Skip if 'document' is a function name
65
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'FunctionDeclaration' && 'id' in parent && parent.id === node) {
66
+ return;
67
+ }
68
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'FunctionExpression' && 'id' in parent && parent.id === node) {
69
+ return;
70
+ }
71
+
72
+ // Skip if 'document' is a method name in a class or object
73
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'MethodDefinition' && parent.key === node) {
74
+ return;
75
+ }
76
+
77
+ // Skip if 'document' is being assigned to (shadowing the global)
78
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'AssignmentExpression' && parent.left === node) {
79
+ return;
80
+ }
81
+
82
+ // Skip if 'document' is in a destructuring pattern (could be destructuring from an object)
83
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ObjectPattern' || (parent === null || parent === void 0 ? void 0 : parent.type) === 'ArrayPattern') {
84
+ return;
85
+ }
86
+ context.report({
87
+ node,
88
+ messageId: 'useGetDocument'
89
+ });
90
+ }
91
+ }
92
+ };
93
+ }
94
+ };
95
+ export default rule;
@@ -0,0 +1,35 @@
1
+ // We will be removing sparse checkout from pipelines in CI completely due to the load it causes on BBC.
2
+ // We will be incrementally removing sparse-checkout from the files below as it is probably unnecessasry.
3
+ // If you must add an exception below, please go through the chopper process before doing so
4
+ const sparseCheckoutExceptions = ['bitbucket-pipelines/pipelines/custom/run-issue-automat.ts', 'bitbucket-pipelines/pipelines/custom/marketplace/utils.ts', 'bitbucket-pipelines/pipelines/custom/confluence/utils/index.ts', 'bitbucket-pipelines/pipelines/custom/afm-tools/upload-afm-dependency-graph-cache.ts', 'bitbucket-pipelines/pipelines/custom/afm-tools/default-afm-tools.ts', 'bitbucket-pipelines/pipelines/custom/marketplace/utils.ts', 'bitbucket-pipelines/pipelines/custom/afm-git-hooks.ts', 'bitbucket-pipelines/pipelines/custom/update-codeowners-and-teams-gen.ts', 'bitbucket-pipelines/pipelines/custom/run-issue-automat.ts'];
5
+ const rule = {
6
+ meta: {
7
+ docs: {
8
+ recommended: false
9
+ },
10
+ type: 'problem',
11
+ messages: {
12
+ noSparseCheckout: 'Sparse checkout is not allowed in pipeline configurations. Use git-alternates instead by setting sparseCheckout to false or add this file to exceptions.'
13
+ }
14
+ },
15
+ create(context) {
16
+ const fileName = context.filename;
17
+ if (sparseCheckoutExceptions.some(exception => fileName.endsWith(exception))) {
18
+ return {};
19
+ }
20
+ return {
21
+ // Look for calls to afmClone or objects that match AFMCloneConfig type
22
+ 'CallExpression[callee.object.name=alias][callee.property.name=afmClone] ObjectExpression Property': node => {
23
+ if (node.key.type === 'Identifier' && node.key.name === 'sparseCheckout') {
24
+ if (node.value.type === 'Literal' && node.value.value === true) {
25
+ context.report({
26
+ node,
27
+ messageId: 'noSparseCheckout'
28
+ });
29
+ }
30
+ }
31
+ }
32
+ };
33
+ }
34
+ };
35
+ export default rule;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Common patterns for test files that should be excluded from rules
3
+ */
4
+ const TEST_FILE_PATTERNS = ['__tests__', 'test', 'spec'];
5
+
6
+ /**
7
+ * Checks if a file should be excluded from rules based on test file patterns
8
+ * @param filename The filename to check
9
+ * @returns true if the file should be excluded, false otherwise
10
+ */
11
+ const isTestFile = filename => {
12
+ return TEST_FILE_PATTERNS.some(pattern => filename.includes(pattern));
13
+ };
14
+
15
+ /**
16
+ * Helper function to skip rules for test files
17
+ * @param context The ESLint rule context
18
+ * @returns An empty RuleListener if the file is a test file, undefined otherwise
19
+ */
20
+ export const skipForTestFiles = context => {
21
+ if (isTestFile(context.filename)) {
22
+ return {};
23
+ }
24
+ return undefined;
25
+ };
26
+
27
+ /**
28
+ * Helper function to skip rules for example files
29
+ * @param context The ESLint rule context
30
+ * @returns An empty RuleListener if the file is an example file, undefined otherwise
31
+ */
32
+ export const skipForExampleFiles = context => {
33
+ if (context.filename.includes('example')) {
34
+ return {};
35
+ }
36
+ return undefined;
37
+ };