@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/dist/esm/index.js CHANGED
@@ -30,6 +30,26 @@ import useEntrypointsInExamples from './rules/use-entrypoints-in-examples';
30
30
  import useRecommendedUtils from './rules/feature-gating/use-recommended-utils';
31
31
  import expandBackgroundShorthand from './rules/compiled/expand-background-shorthand';
32
32
  import expandSpacingShorthand from './rules/compiled/expand-spacing-shorthand';
33
+ import noSparseCheckout from './rules/no-sparse-checkout';
34
+ import noDirectDocumentUsage from './rules/no-direct-document-usage';
35
+ import { join, normalize } from 'node:path';
36
+ import { readFileSync } from 'node:fs';
37
+ var jiraRoot;
38
+ try {
39
+ var findUp = require('find-up');
40
+ findUp.sync(function (dir) {
41
+ var productsJsonPath = join(dir, 'products.json');
42
+ if (findUp.sync.exists(productsJsonPath)) {
43
+ var productJson = JSON.parse(readFileSync(productsJsonPath, 'utf-8'));
44
+ if (productJson.Jira) {
45
+ jiraRoot = normalize(join(dir, productJson.Jira.path));
46
+ return findUp.stop;
47
+ }
48
+ }
49
+ });
50
+ } catch (_unused) {
51
+ // we aren't running inside of AFM, so we can ignore this.
52
+ }
33
53
  var packageJson = require('@atlaskit/eslint-plugin-platform/package.json');
34
54
  var rules = {
35
55
  'ensure-feature-flag-registration': ensureFeatureFlagRegistration,
@@ -58,7 +78,9 @@ var rules = {
58
78
  'prefer-fg': preferFG,
59
79
  'no-alias': noAlias,
60
80
  'use-entrypoints-in-examples': useEntrypointsInExamples,
61
- 'use-recommended-utils': useRecommendedUtils
81
+ 'use-recommended-utils': useRecommendedUtils,
82
+ 'no-sparse-checkout': noSparseCheckout,
83
+ 'no-direct-document-usage': noDirectDocumentUsage
62
84
  };
63
85
  var commonConfig = {
64
86
  '@atlaskit/platform/ensure-test-runner-arguments': 'error',
@@ -67,6 +89,7 @@ var commonConfig = {
67
89
  '@atlaskit/platform/no-invalid-storybook-decorator-usage': 'error',
68
90
  '@atlaskit/platform/ensure-atlassian-team': 'error',
69
91
  '@atlaskit/platform/no-module-level-eval-nav4': 'error',
92
+ '@atlaskit/platform/no-direct-document-usage': 'warn',
70
93
  // Compiled: rules that are not included via `@compiled/recommended
71
94
  '@atlaskit/platform/expand-border-shorthand': 'error',
72
95
  '@atlaskit/platform/expand-background-shorthand': 'error',
@@ -95,6 +118,7 @@ var recommendedRules = _objectSpread(_objectSpread({}, commonConfig), {}, {
95
118
  var jiraRules = commonConfig;
96
119
  var jsonPrefix = '/* eslint-disable quote-props, comma-dangle, quotes, semi, eol-last, @typescript-eslint/semi, no-template-curly-in-string */ module.exports = ';
97
120
  var jsonPrefixForFlatConfig = '/* eslint-disable quote-props, comma-dangle, quotes, semi, eol-last, no-template-curly-in-string */ module.exports = ';
121
+ var jsonPrefixForJira = 'module.exports = ';
98
122
  var name = packageJson.name,
99
123
  version = packageJson.version;
100
124
  var plugin = {
@@ -141,7 +165,14 @@ var plugin = {
141
165
  },
142
166
  processors: {
143
167
  'package-json-processor': {
144
- preprocess: function preprocess(source) {
168
+ preprocess: function 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
  },
@@ -164,7 +195,13 @@ var plugin = {
164
195
  // This processor is used for ESLint FlatConfig,
165
196
  // once we roll out FlatConfig, we can remove the above processor
166
197
  'package-json-processor-for-flat-config': {
167
- preprocess: function preprocess(source) {
198
+ // we only need to check for jiraRoot because it uses a different
199
+ // ESLint version and produces fake errors due to how this processor handles JSON
200
+ preprocess: function preprocess(source, filename) {
201
+ if (jiraRoot && filename.startsWith(jiraRoot)) {
202
+ // augment the json into a js file
203
+ return [jsonPrefixForJira + source.trim()];
204
+ }
168
205
  // augment the json into a js file
169
206
  return [jsonPrefixForFlatConfig + source.trim()];
170
207
  },
@@ -6,6 +6,9 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
6
6
  import path from 'path';
7
7
  import { getMetadataForFilename } from '../util/registration-utils';
8
8
  var exportsValidationExceptions = {
9
+ '@af/yarn-workspace': {
10
+ ignoredAfExportKeys: ['./lock-parser']
11
+ },
9
12
  '@atlaskit/tokens': {
10
13
  ignoredAfExportKeys: ['./babel-plugin']
11
14
  },
@@ -49,7 +49,7 @@ var rule = {
49
49
  },
50
50
  hasSuggestions: false,
51
51
  messages: {
52
- invalidWorkspaceProtocolUsage: "The 'workspace:^' or 'workspace:~' protocol is Used. To resolve this error, please use the 'workspace:*' protocol instead.",
52
+ invalidWorkspaceProtocolUsage: "The 'workspace:^'protocol is Used. To resolve this error, please use the 'workspace:*' protocol instead.",
53
53
  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')."
54
54
  }
55
55
  },
@@ -49,7 +49,7 @@ var rule = {
49
49
  url: 'https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo/browse/platform/packages/platform/eslint-plugin/src/rules/no-preconditioning/README.md'
50
50
  },
51
51
  messages: {
52
- useConfig: 'Do not precondition gates or experiments with another gate. Configure this in Statsig instead to reduce unnecessary code and simplify cleanup.',
52
+ 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.',
53
53
  incorrectExposure: 'Evaluate gates or experiments at the end of your logical expression to ensure exposure is tracked correctly.'
54
54
  }
55
55
  },
@@ -0,0 +1,97 @@
1
+ import { skipForExampleFiles, skipForTestFiles } from '../util/file-exclusions';
2
+ var 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: function create(context) {
15
+ var hasGetDocumentImport = false;
16
+ var filename = context.filename;
17
+
18
+ // Skip test files
19
+ var skipResult = skipForTestFiles(context);
20
+ if (skipResult) {
21
+ return skipResult;
22
+ }
23
+
24
+ // Skip example files
25
+ var 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: function ImportDeclaration(node) {
36
+ if (node.source.value === '@atlaskit/browser-apis' && node.specifiers.some(function (specifier) {
37
+ return specifier.type === 'ImportSpecifier' && specifier.imported.name === 'getDocument';
38
+ })) {
39
+ hasGetDocumentImport = true;
40
+ }
41
+ },
42
+ Identifier: function Identifier(node) {
43
+ if (node.name === 'document' && !hasGetDocumentImport) {
44
+ var parent = node.parent;
45
+
46
+ // Skip if 'document' is used as a property key in an object literal
47
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Property' && parent.key === node) {
48
+ return;
49
+ }
50
+
51
+ // Skip if 'document' is used as a shorthand property value
52
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Property' && parent.value === node && parent.shorthand) {
53
+ return;
54
+ }
55
+
56
+ // Skip if 'document' is used as a property being accessed in a member expression
57
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'MemberExpression' && parent.property === node && !parent.computed) {
58
+ return;
59
+ }
60
+
61
+ // Skip if 'document' is being declared as a variable
62
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'VariableDeclarator' && parent.id === node) {
63
+ return;
64
+ }
65
+
66
+ // Skip if 'document' is a function name
67
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'FunctionDeclaration' && 'id' in parent && parent.id === node) {
68
+ return;
69
+ }
70
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'FunctionExpression' && 'id' in parent && parent.id === node) {
71
+ return;
72
+ }
73
+
74
+ // Skip if 'document' is a method name in a class or object
75
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'MethodDefinition' && parent.key === node) {
76
+ return;
77
+ }
78
+
79
+ // Skip if 'document' is being assigned to (shadowing the global)
80
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'AssignmentExpression' && parent.left === node) {
81
+ return;
82
+ }
83
+
84
+ // Skip if 'document' is in a destructuring pattern (could be destructuring from an object)
85
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ObjectPattern' || (parent === null || parent === void 0 ? void 0 : parent.type) === 'ArrayPattern') {
86
+ return;
87
+ }
88
+ context.report({
89
+ node: node,
90
+ messageId: 'useGetDocument'
91
+ });
92
+ }
93
+ }
94
+ };
95
+ }
96
+ };
97
+ export default rule;
@@ -0,0 +1,37 @@
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
+ 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'];
5
+ var 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: function create(context) {
16
+ var fileName = context.filename;
17
+ if (sparseCheckoutExceptions.some(function (exception) {
18
+ return fileName.endsWith(exception);
19
+ })) {
20
+ return {};
21
+ }
22
+ return {
23
+ // Look for calls to afmClone or objects that match AFMCloneConfig type
24
+ 'CallExpression[callee.object.name=alias][callee.property.name=afmClone] ObjectExpression Property': function CallExpressionCalleeObjectNameAliasCalleePropertyNameAfmClone_ObjectExpression_Property(node) {
25
+ if (node.key.type === 'Identifier' && node.key.name === 'sparseCheckout') {
26
+ if (node.value.type === 'Literal' && node.value.value === true) {
27
+ context.report({
28
+ node: node,
29
+ messageId: 'noSparseCheckout'
30
+ });
31
+ }
32
+ }
33
+ }
34
+ };
35
+ }
36
+ };
37
+ export default rule;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Common patterns for test files that should be excluded from rules
3
+ */
4
+ var 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
+ var isTestFile = function isTestFile(filename) {
12
+ return TEST_FILE_PATTERNS.some(function (pattern) {
13
+ return filename.includes(pattern);
14
+ });
15
+ };
16
+
17
+ /**
18
+ * Helper function to skip rules for test files
19
+ * @param context The ESLint rule context
20
+ * @returns An empty RuleListener if the file is a test file, undefined otherwise
21
+ */
22
+ export var skipForTestFiles = function skipForTestFiles(context) {
23
+ if (isTestFile(context.filename)) {
24
+ return {};
25
+ }
26
+ return undefined;
27
+ };
28
+
29
+ /**
30
+ * Helper function to skip rules for example files
31
+ * @param context The ESLint rule context
32
+ * @returns An empty RuleListener if the file is an example file, undefined otherwise
33
+ */
34
+ export var skipForExampleFiles = function skipForExampleFiles(context) {
35
+ if (context.filename.includes('example')) {
36
+ return {};
37
+ }
38
+ return undefined;
39
+ };
@@ -27,6 +27,8 @@ declare const rules: {
27
27
  'no-alias': import("eslint").Rule.RuleModule;
28
28
  'use-entrypoints-in-examples': import("eslint").Rule.RuleModule;
29
29
  'use-recommended-utils': import("eslint").Rule.RuleModule;
30
+ 'no-sparse-checkout': import("eslint").Rule.RuleModule;
31
+ 'no-direct-document-usage': import("eslint").Rule.RuleModule;
30
32
  };
31
33
  declare const plugin: {
32
34
  meta: {
@@ -61,6 +63,8 @@ declare const plugin: {
61
63
  'no-alias': import("eslint").Rule.RuleModule;
62
64
  'use-entrypoints-in-examples': import("eslint").Rule.RuleModule;
63
65
  'use-recommended-utils': import("eslint").Rule.RuleModule;
66
+ 'no-sparse-checkout': import("eslint").Rule.RuleModule;
67
+ 'no-direct-document-usage': import("eslint").Rule.RuleModule;
64
68
  };
65
69
  configs: {
66
70
  recommended: {
@@ -82,6 +86,7 @@ declare const plugin: {
82
86
  '@atlaskit/platform/no-invalid-storybook-decorator-usage': "error";
83
87
  '@atlaskit/platform/ensure-atlassian-team': "error";
84
88
  '@atlaskit/platform/no-module-level-eval-nav4': "error";
89
+ '@atlaskit/platform/no-direct-document-usage': "warn";
85
90
  '@atlaskit/platform/expand-border-shorthand': "error";
86
91
  '@atlaskit/platform/expand-background-shorthand': "error";
87
92
  '@atlaskit/platform/expand-spacing-shorthand': "error";
@@ -114,6 +119,7 @@ declare const plugin: {
114
119
  '@atlaskit/platform/no-invalid-storybook-decorator-usage': "error";
115
120
  '@atlaskit/platform/ensure-atlassian-team': "error";
116
121
  '@atlaskit/platform/no-module-level-eval-nav4': "error";
122
+ '@atlaskit/platform/no-direct-document-usage': "warn";
117
123
  '@atlaskit/platform/expand-border-shorthand': "error";
118
124
  '@atlaskit/platform/expand-background-shorthand': "error";
119
125
  '@atlaskit/platform/expand-spacing-shorthand': "error";
@@ -133,6 +139,7 @@ declare const plugin: {
133
139
  '@atlaskit/platform/no-invalid-storybook-decorator-usage': "error";
134
140
  '@atlaskit/platform/ensure-atlassian-team': "error";
135
141
  '@atlaskit/platform/no-module-level-eval-nav4': "error";
142
+ '@atlaskit/platform/no-direct-document-usage': "warn";
136
143
  '@atlaskit/platform/expand-border-shorthand': "error";
137
144
  '@atlaskit/platform/expand-background-shorthand': "error";
138
145
  '@atlaskit/platform/expand-spacing-shorthand': "error";
@@ -155,6 +162,7 @@ declare const plugin: {
155
162
  '@atlaskit/platform/no-invalid-storybook-decorator-usage': "error";
156
163
  '@atlaskit/platform/ensure-atlassian-team': "error";
157
164
  '@atlaskit/platform/no-module-level-eval-nav4': "error";
165
+ '@atlaskit/platform/no-direct-document-usage': "warn";
158
166
  '@atlaskit/platform/expand-border-shorthand': "error";
159
167
  '@atlaskit/platform/expand-background-shorthand': "error";
160
168
  '@atlaskit/platform/expand-spacing-shorthand': "error";
@@ -191,6 +199,7 @@ declare const configs: {
191
199
  '@atlaskit/platform/no-invalid-storybook-decorator-usage': "error";
192
200
  '@atlaskit/platform/ensure-atlassian-team': "error";
193
201
  '@atlaskit/platform/no-module-level-eval-nav4': "error";
202
+ '@atlaskit/platform/no-direct-document-usage': "warn";
194
203
  '@atlaskit/platform/expand-border-shorthand': "error";
195
204
  '@atlaskit/platform/expand-background-shorthand': "error";
196
205
  '@atlaskit/platform/expand-spacing-shorthand': "error";
@@ -223,6 +232,7 @@ declare const configs: {
223
232
  '@atlaskit/platform/no-invalid-storybook-decorator-usage': "error";
224
233
  '@atlaskit/platform/ensure-atlassian-team': "error";
225
234
  '@atlaskit/platform/no-module-level-eval-nav4': "error";
235
+ '@atlaskit/platform/no-direct-document-usage': "warn";
226
236
  '@atlaskit/platform/expand-border-shorthand': "error";
227
237
  '@atlaskit/platform/expand-background-shorthand': "error";
228
238
  '@atlaskit/platform/expand-spacing-shorthand': "error";
@@ -242,6 +252,7 @@ declare const configs: {
242
252
  '@atlaskit/platform/no-invalid-storybook-decorator-usage': "error";
243
253
  '@atlaskit/platform/ensure-atlassian-team': "error";
244
254
  '@atlaskit/platform/no-module-level-eval-nav4': "error";
255
+ '@atlaskit/platform/no-direct-document-usage': "warn";
245
256
  '@atlaskit/platform/expand-border-shorthand': "error";
246
257
  '@atlaskit/platform/expand-background-shorthand': "error";
247
258
  '@atlaskit/platform/expand-spacing-shorthand': "error";
@@ -264,6 +275,7 @@ declare const configs: {
264
275
  '@atlaskit/platform/no-invalid-storybook-decorator-usage': "error";
265
276
  '@atlaskit/platform/ensure-atlassian-team': "error";
266
277
  '@atlaskit/platform/no-module-level-eval-nav4': "error";
278
+ '@atlaskit/platform/no-direct-document-usage': "warn";
267
279
  '@atlaskit/platform/expand-border-shorthand': "error";
268
280
  '@atlaskit/platform/expand-background-shorthand': "error";
269
281
  '@atlaskit/platform/expand-spacing-shorthand': "error";
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -0,0 +1,13 @@
1
+ import type { Rule } from 'eslint';
2
+ /**
3
+ * Helper function to skip rules for test files
4
+ * @param context The ESLint rule context
5
+ * @returns An empty RuleListener if the file is a test file, undefined otherwise
6
+ */
7
+ export declare const skipForTestFiles: (context: Rule.RuleContext) => Rule.RuleListener | undefined;
8
+ /**
9
+ * Helper function to skip rules for example files
10
+ * @param context The ESLint rule context
11
+ * @returns An empty RuleListener if the file is an example file, undefined otherwise
12
+ */
13
+ export declare const skipForExampleFiles: (context: Rule.RuleContext) => Rule.RuleListener | undefined;
@@ -27,6 +27,8 @@ declare const rules: {
27
27
  'no-alias': import("eslint").Rule.RuleModule;
28
28
  'use-entrypoints-in-examples': import("eslint").Rule.RuleModule;
29
29
  'use-recommended-utils': import("eslint").Rule.RuleModule;
30
+ 'no-sparse-checkout': import("eslint").Rule.RuleModule;
31
+ 'no-direct-document-usage': import("eslint").Rule.RuleModule;
30
32
  };
31
33
  declare const plugin: {
32
34
  meta: {
@@ -61,6 +63,8 @@ declare const plugin: {
61
63
  'no-alias': import("eslint").Rule.RuleModule;
62
64
  'use-entrypoints-in-examples': import("eslint").Rule.RuleModule;
63
65
  'use-recommended-utils': import("eslint").Rule.RuleModule;
66
+ 'no-sparse-checkout': import("eslint").Rule.RuleModule;
67
+ 'no-direct-document-usage': import("eslint").Rule.RuleModule;
64
68
  };
65
69
  configs: {
66
70
  recommended: {
@@ -85,6 +89,7 @@ declare const plugin: {
85
89
  '@atlaskit/platform/no-invalid-storybook-decorator-usage': "error";
86
90
  '@atlaskit/platform/ensure-atlassian-team': "error";
87
91
  '@atlaskit/platform/no-module-level-eval-nav4': "error";
92
+ '@atlaskit/platform/no-direct-document-usage': "warn";
88
93
  '@atlaskit/platform/expand-border-shorthand': "error";
89
94
  '@atlaskit/platform/expand-background-shorthand': "error";
90
95
  '@atlaskit/platform/expand-spacing-shorthand': "error";
@@ -123,6 +128,7 @@ declare const plugin: {
123
128
  '@atlaskit/platform/no-invalid-storybook-decorator-usage': "error";
124
129
  '@atlaskit/platform/ensure-atlassian-team': "error";
125
130
  '@atlaskit/platform/no-module-level-eval-nav4': "error";
131
+ '@atlaskit/platform/no-direct-document-usage': "warn";
126
132
  '@atlaskit/platform/expand-border-shorthand': "error";
127
133
  '@atlaskit/platform/expand-background-shorthand': "error";
128
134
  '@atlaskit/platform/expand-spacing-shorthand': "error";
@@ -145,6 +151,7 @@ declare const plugin: {
145
151
  '@atlaskit/platform/no-invalid-storybook-decorator-usage': "error";
146
152
  '@atlaskit/platform/ensure-atlassian-team': "error";
147
153
  '@atlaskit/platform/no-module-level-eval-nav4': "error";
154
+ '@atlaskit/platform/no-direct-document-usage': "warn";
148
155
  '@atlaskit/platform/expand-border-shorthand': "error";
149
156
  '@atlaskit/platform/expand-background-shorthand': "error";
150
157
  '@atlaskit/platform/expand-spacing-shorthand': "error";
@@ -170,6 +177,7 @@ declare const plugin: {
170
177
  '@atlaskit/platform/no-invalid-storybook-decorator-usage': "error";
171
178
  '@atlaskit/platform/ensure-atlassian-team': "error";
172
179
  '@atlaskit/platform/no-module-level-eval-nav4': "error";
180
+ '@atlaskit/platform/no-direct-document-usage': "warn";
173
181
  '@atlaskit/platform/expand-border-shorthand': "error";
174
182
  '@atlaskit/platform/expand-background-shorthand': "error";
175
183
  '@atlaskit/platform/expand-spacing-shorthand': "error";
@@ -212,6 +220,7 @@ declare const configs: {
212
220
  '@atlaskit/platform/no-invalid-storybook-decorator-usage': "error";
213
221
  '@atlaskit/platform/ensure-atlassian-team': "error";
214
222
  '@atlaskit/platform/no-module-level-eval-nav4': "error";
223
+ '@atlaskit/platform/no-direct-document-usage': "warn";
215
224
  '@atlaskit/platform/expand-border-shorthand': "error";
216
225
  '@atlaskit/platform/expand-background-shorthand': "error";
217
226
  '@atlaskit/platform/expand-spacing-shorthand': "error";
@@ -250,6 +259,7 @@ declare const configs: {
250
259
  '@atlaskit/platform/no-invalid-storybook-decorator-usage': "error";
251
260
  '@atlaskit/platform/ensure-atlassian-team': "error";
252
261
  '@atlaskit/platform/no-module-level-eval-nav4': "error";
262
+ '@atlaskit/platform/no-direct-document-usage': "warn";
253
263
  '@atlaskit/platform/expand-border-shorthand': "error";
254
264
  '@atlaskit/platform/expand-background-shorthand': "error";
255
265
  '@atlaskit/platform/expand-spacing-shorthand': "error";
@@ -272,6 +282,7 @@ declare const configs: {
272
282
  '@atlaskit/platform/no-invalid-storybook-decorator-usage': "error";
273
283
  '@atlaskit/platform/ensure-atlassian-team': "error";
274
284
  '@atlaskit/platform/no-module-level-eval-nav4': "error";
285
+ '@atlaskit/platform/no-direct-document-usage': "warn";
275
286
  '@atlaskit/platform/expand-border-shorthand': "error";
276
287
  '@atlaskit/platform/expand-background-shorthand': "error";
277
288
  '@atlaskit/platform/expand-spacing-shorthand': "error";
@@ -297,6 +308,7 @@ declare const configs: {
297
308
  '@atlaskit/platform/no-invalid-storybook-decorator-usage': "error";
298
309
  '@atlaskit/platform/ensure-atlassian-team': "error";
299
310
  '@atlaskit/platform/no-module-level-eval-nav4': "error";
311
+ '@atlaskit/platform/no-direct-document-usage': "warn";
300
312
  '@atlaskit/platform/expand-border-shorthand': "error";
301
313
  '@atlaskit/platform/expand-background-shorthand': "error";
302
314
  '@atlaskit/platform/expand-spacing-shorthand': "error";
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -0,0 +1,13 @@
1
+ import type { Rule } from 'eslint';
2
+ /**
3
+ * Helper function to skip rules for test files
4
+ * @param context The ESLint rule context
5
+ * @returns An empty RuleListener if the file is a test file, undefined otherwise
6
+ */
7
+ export declare const skipForTestFiles: (context: Rule.RuleContext) => Rule.RuleListener | undefined;
8
+ /**
9
+ * Helper function to skip rules for example files
10
+ * @param context The ESLint rule context
11
+ * @returns An empty RuleListener if the file is an example file, undefined otherwise
12
+ */
13
+ export declare const skipForExampleFiles: (context: Rule.RuleContext) => Rule.RuleListener | undefined;
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": "2.5.0",
4
+ "version": "2.6.0",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "atlassian": {
7
7
  "team": "Build Infra",
@@ -45,6 +45,15 @@
45
45
  "@atlassian/ts-loader": "^0.1.0",
46
46
  "@types/eslint": "^8.56.6",
47
47
  "eslint": "^8.57.0",
48
+ "find-up": "^4 || ^5",
48
49
  "outdent": "^0.5.0"
50
+ },
51
+ "peerDependencies": {
52
+ "find-up": "^4 || ^5"
53
+ },
54
+ "peerDependenciesMeta": {
55
+ "find-up": {
56
+ "optional": true
57
+ }
49
58
  }
50
59
  }
package/src/index.tsx CHANGED
@@ -28,6 +28,30 @@ import useEntrypointsInExamples from './rules/use-entrypoints-in-examples';
28
28
  import useRecommendedUtils from './rules/feature-gating/use-recommended-utils';
29
29
  import expandBackgroundShorthand from './rules/compiled/expand-background-shorthand';
30
30
  import expandSpacingShorthand from './rules/compiled/expand-spacing-shorthand';
31
+ import noSparseCheckout from './rules/no-sparse-checkout';
32
+ import noDirectDocumentUsage from './rules/no-direct-document-usage';
33
+ import { join, normalize } from 'node:path';
34
+ import { readFileSync } from 'node:fs';
35
+
36
+ let jiraRoot: string | undefined;
37
+
38
+ try {
39
+ const findUp = require('find-up') as typeof import('find-up');
40
+ findUp.sync((dir) => {
41
+ const productsJsonPath = join(dir, 'products.json');
42
+ if (findUp.sync.exists(productsJsonPath)) {
43
+ const productJson: Record<string, { path: string }> = JSON.parse(
44
+ readFileSync(productsJsonPath, 'utf-8'),
45
+ );
46
+ if (productJson.Jira) {
47
+ jiraRoot = normalize(join(dir, productJson.Jira.path));
48
+ return findUp.stop;
49
+ }
50
+ }
51
+ });
52
+ } catch {
53
+ // we aren't running inside of AFM, so we can ignore this.
54
+ }
31
55
 
32
56
  const packageJson: {
33
57
  name: string;
@@ -63,6 +87,8 @@ const rules = {
63
87
  'no-alias': noAlias,
64
88
  'use-entrypoints-in-examples': useEntrypointsInExamples,
65
89
  'use-recommended-utils': useRecommendedUtils,
90
+ 'no-sparse-checkout': noSparseCheckout,
91
+ 'no-direct-document-usage': noDirectDocumentUsage,
66
92
  };
67
93
 
68
94
  const commonConfig = {
@@ -72,6 +98,7 @@ const commonConfig = {
72
98
  '@atlaskit/platform/no-invalid-storybook-decorator-usage': 'error',
73
99
  '@atlaskit/platform/ensure-atlassian-team': 'error',
74
100
  '@atlaskit/platform/no-module-level-eval-nav4': 'error',
101
+ '@atlaskit/platform/no-direct-document-usage': 'warn',
75
102
  // Compiled: rules that are not included via `@compiled/recommended
76
103
  '@atlaskit/platform/expand-border-shorthand': 'error',
77
104
  '@atlaskit/platform/expand-background-shorthand': 'error',
@@ -112,6 +139,8 @@ const jsonPrefix =
112
139
  const jsonPrefixForFlatConfig =
113
140
  '/* eslint-disable quote-props, comma-dangle, quotes, semi, eol-last, no-template-curly-in-string */ module.exports = ';
114
141
 
142
+ const jsonPrefixForJira = 'module.exports = ';
143
+
115
144
  const { name, version } = packageJson;
116
145
  const plugin = {
117
146
  meta: {
@@ -151,7 +180,14 @@ const plugin = {
151
180
  },
152
181
  processors: {
153
182
  'package-json-processor': {
154
- preprocess: (source: string) => {
183
+ preprocess: (source, filename) => {
184
+ // we only need to check for jiraRoot because it uses a different
185
+ // ESLint version and produces fake errors due to how this processor handles JSON
186
+ if (jiraRoot && filename.startsWith(jiraRoot)) {
187
+ // augment the json into a js file
188
+ return [jsonPrefixForJira + source.trim()];
189
+ }
190
+
155
191
  // augment the json into a js file
156
192
  return [jsonPrefix + source.trim()];
157
193
  },
@@ -177,7 +213,13 @@ const plugin = {
177
213
  // This processor is used for ESLint FlatConfig,
178
214
  // once we roll out FlatConfig, we can remove the above processor
179
215
  'package-json-processor-for-flat-config': {
180
- preprocess: (source: string) => {
216
+ // we only need to check for jiraRoot because it uses a different
217
+ // ESLint version and produces fake errors due to how this processor handles JSON
218
+ preprocess: (source, filename) => {
219
+ if (jiraRoot && filename.startsWith(jiraRoot)) {
220
+ // augment the json into a js file
221
+ return [jsonPrefixForJira + source.trim()];
222
+ }
181
223
  // augment the json into a js file
182
224
  return [jsonPrefixForFlatConfig + source.trim()];
183
225
  },
@@ -8,6 +8,9 @@ interface ExportsValidationExceptions {
8
8
  }
9
9
 
10
10
  const exportsValidationExceptions: ExportsValidationExceptions = {
11
+ '@af/yarn-workspace': {
12
+ ignoredAfExportKeys: ['./lock-parser'],
13
+ },
11
14
  '@atlaskit/tokens': {
12
15
  ignoredAfExportKeys: ['./babel-plugin'],
13
16
  },
@@ -16,8 +16,9 @@ jest.mock('fs', () => {
16
16
  const actual = jest.requireActual('fs');
17
17
  return {
18
18
  ...actual,
19
- statSync: jest.fn((stat: string) => ({
20
- isFile: jest.fn(() => mockValidBinPaths.includes(stat)),
19
+ statSync: jest.fn((p: string) => ({
20
+ isFile: jest.fn(() => mockValidBinPaths.includes(p)),
21
+ isDirectory: jest.fn(() => actual.statSync(p).isDirectory()),
21
22
  })),
22
23
  };
23
24
  });
@@ -39,7 +39,7 @@ const rule: Rule.RuleModule = {
39
39
  },
40
40
  hasSuggestions: false,
41
41
  messages: {
42
- invalidWorkspaceProtocolUsage: `The 'workspace:^' or 'workspace:~' protocol is Used. To resolve this error, please use the 'workspace:*' protocol instead.`,
42
+ invalidWorkspaceProtocolUsage: `The 'workspace:^'protocol is Used. To resolve this error, please use the 'workspace:*' protocol instead.`,
43
43
  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').`,
44
44
  },
45
45
  },