@atlaskit/eslint-plugin-platform 0.2.1 → 0.2.3

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/eslint-plugin-platform
2
2
 
3
+ ## 0.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`0bf64fb3dd0`](https://bitbucket.org/atlassian/atlassian-frontend/commits/0bf64fb3dd0) - Update to support unary expressions like negation
8
+
9
+ ## 0.2.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [`9d00501a414`](https://bitbucket.org/atlassian/atlassian-frontend/commits/9d00501a414) - Ensure legacy types are published for TS 4.5-4.8
14
+
3
15
  ## 0.2.1
4
16
 
5
17
  ### Patch Changes
@@ -11,6 +11,8 @@ var __isOnlyOneFlagCheckInExpression = function __isOnlyOneFlagCheckInExpression
11
11
  switch (root.type) {
12
12
  case 'IfStatement':
13
13
  return __isOnlyOneFlagCheckInExpression(root.test, ignoredNode);
14
+ case 'UnaryExpression':
15
+ return __isOnlyOneFlagCheckInExpression(root.argument, ignoredNode);
14
16
  case 'CallExpression':
15
17
  if (root === ignoredNode) {
16
18
  return true;
@@ -30,7 +32,8 @@ var __isOnlyOneFlagCheckInExpression = function __isOnlyOneFlagCheckInExpression
30
32
  var isOnlyOneFlagCheckInExpression = function isOnlyOneFlagCheckInExpression(node) {
31
33
  var root = node.parent;
32
34
  // find the root node of the expression
33
- while (root.type === 'LogicalExpression') {
35
+ // NOTE: This is not an exhaustive check for all ESTree.Expression types but is good enough
36
+ while (root.type.endsWith('Expression')) {
34
37
  root = root.parent;
35
38
  }
36
39
  return __isOnlyOneFlagCheckInExpression(root, node);
@@ -64,6 +67,7 @@ var rule = {
64
67
  case 'IfStatement':
65
68
  case 'ConditionalExpression':
66
69
  break;
70
+ case 'UnaryExpression':
67
71
  case 'LogicalExpression':
68
72
  if (!isOnlyOneFlagCheckInExpression(node)) {
69
73
  context.report({
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-platform",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "sideEffects": false
5
5
  }
@@ -3,6 +3,8 @@ const __isOnlyOneFlagCheckInExpression = (root, ignoredNode) => {
3
3
  switch (root.type) {
4
4
  case 'IfStatement':
5
5
  return __isOnlyOneFlagCheckInExpression(root.test, ignoredNode);
6
+ case 'UnaryExpression':
7
+ return __isOnlyOneFlagCheckInExpression(root.argument, ignoredNode);
6
8
  case 'CallExpression':
7
9
  if (root === ignoredNode) {
8
10
  return true;
@@ -22,7 +24,8 @@ const __isOnlyOneFlagCheckInExpression = (root, ignoredNode) => {
22
24
  const isOnlyOneFlagCheckInExpression = node => {
23
25
  let root = node.parent;
24
26
  // find the root node of the expression
25
- while (root.type === 'LogicalExpression') {
27
+ // NOTE: This is not an exhaustive check for all ESTree.Expression types but is good enough
28
+ while (root.type.endsWith('Expression')) {
26
29
  root = root.parent;
27
30
  }
28
31
  return __isOnlyOneFlagCheckInExpression(root, node);
@@ -57,6 +60,7 @@ const rule = {
57
60
  case 'IfStatement':
58
61
  case 'ConditionalExpression':
59
62
  break;
63
+ case 'UnaryExpression':
60
64
  case 'LogicalExpression':
61
65
  if (!isOnlyOneFlagCheckInExpression(node)) {
62
66
  context.report({
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-platform",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "sideEffects": false
5
5
  }
@@ -4,6 +4,8 @@ var __isOnlyOneFlagCheckInExpression = function __isOnlyOneFlagCheckInExpression
4
4
  switch (root.type) {
5
5
  case 'IfStatement':
6
6
  return __isOnlyOneFlagCheckInExpression(root.test, ignoredNode);
7
+ case 'UnaryExpression':
8
+ return __isOnlyOneFlagCheckInExpression(root.argument, ignoredNode);
7
9
  case 'CallExpression':
8
10
  if (root === ignoredNode) {
9
11
  return true;
@@ -23,7 +25,8 @@ var __isOnlyOneFlagCheckInExpression = function __isOnlyOneFlagCheckInExpression
23
25
  var isOnlyOneFlagCheckInExpression = function isOnlyOneFlagCheckInExpression(node) {
24
26
  var root = node.parent;
25
27
  // find the root node of the expression
26
- while (root.type === 'LogicalExpression') {
28
+ // NOTE: This is not an exhaustive check for all ESTree.Expression types but is good enough
29
+ while (root.type.endsWith('Expression')) {
27
30
  root = root.parent;
28
31
  }
29
32
  return __isOnlyOneFlagCheckInExpression(root, node);
@@ -57,6 +60,7 @@ var rule = {
57
60
  case 'IfStatement':
58
61
  case 'ConditionalExpression':
59
62
  break;
63
+ case 'UnaryExpression':
60
64
  case 'LogicalExpression':
61
65
  if (!isOnlyOneFlagCheckInExpression(node)) {
62
66
  context.report({
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-platform",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,28 @@
1
+ import type { Linter } from 'eslint';
2
+ export declare const rules: {
3
+ 'ensure-feature-flag-registration': import("eslint").Rule.RuleModule;
4
+ 'ensure-feature-flag-prefix': import("eslint").Rule.RuleModule;
5
+ 'ensure-test-runner-arguments': import("eslint").Rule.RuleModule;
6
+ 'ensure-test-runner-nested-count': import("eslint").Rule.RuleModule;
7
+ 'no-invalid-feature-flag-usage': import("eslint").Rule.RuleModule;
8
+ 'no-pre-post-install-scripts': import("eslint").Rule.RuleModule;
9
+ 'no-invalid-storybook-decorator-usage': import("eslint").Rule.RuleModule;
10
+ };
11
+ export declare const configs: {
12
+ recommended: {
13
+ plugins: string[];
14
+ rules: {
15
+ '@atlaskit/platform/ensure-feature-flag-registration': string;
16
+ '@atlaskit/platform/ensure-feature-flag-prefix': (string | {
17
+ allowedPrefixes: string[];
18
+ })[];
19
+ '@atlaskit/platform/ensure-test-runner-arguments': string;
20
+ '@atlaskit/platform/ensure-test-runner-nested-count': string;
21
+ '@atlaskit/platform/no-invalid-feature-flag-usage': string;
22
+ '@atlaskit/platform/no-invalid-storybook-decorator-usage': string;
23
+ };
24
+ };
25
+ };
26
+ export declare const processors: {
27
+ 'package-json-processor': Linter.Processor<string | Linter.ProcessorFile>;
28
+ };
@@ -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,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,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,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -0,0 +1,19 @@
1
+ import readPkgUp from 'read-pkg-up';
2
+ import Fuse from 'fuse.js';
3
+ export declare const getterIdentifierToFlagTypeMap: {
4
+ readonly getBooleanFF: "boolean";
5
+ readonly ffTest: "boolean";
6
+ };
7
+ export type PlatformFeatureFlagRegistrationSection = {
8
+ [key: string]: {
9
+ type: (typeof getterIdentifierToFlagTypeMap)[keyof typeof getterIdentifierToFlagTypeMap];
10
+ };
11
+ };
12
+ export type EnhancedPackageJson = readPkgUp.PackageJson & {
13
+ 'platform-feature-flags'?: PlatformFeatureFlagRegistrationSection;
14
+ };
15
+ export type PkgJsonMetaData = {
16
+ pkgJson: EnhancedPackageJson;
17
+ fuse: Fuse<string> | null;
18
+ };
19
+ export declare const getMetadataForFilename: (filename: string) => PkgJsonMetaData;
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.2.1",
4
+ "version": "0.2.3",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "atlassian": {
7
7
  "team": "UIP - Platform Integration Trust (PITa)",
@@ -8,6 +8,10 @@ describe('enforce-feature-flag-usage-structure tests', () => {
8
8
  // IfStatement
9
9
  code: `if(getBooleanFF('test-flag')) { }`,
10
10
  },
11
+ {
12
+ // negated IfStatement
13
+ code: `if(!getBooleanFF('test-flag')) { }`,
14
+ },
11
15
  {
12
16
  // ConditionalExpression
13
17
  code: `const val = getBooleanFF('test-flag') ? 'yay' : 'no';`,
@@ -38,7 +42,14 @@ describe('enforce-feature-flag-usage-structure tests', () => {
38
42
  ],
39
43
  },
40
44
  {
41
- code: `if((getBooleanFF('test-flag') || 1 == true) && getBooleanFF('test-flag')) { }`,
45
+ code: `if(!getBooleanFF('test-flag') && !getBooleanFF('test-flag')) { }`,
46
+ errors: [
47
+ { messageId: 'multipleFlagCheckInExpression' },
48
+ { messageId: 'multipleFlagCheckInExpression' },
49
+ ],
50
+ },
51
+ {
52
+ code: `if((!getBooleanFF('test-flag') || 1 == true) && getBooleanFF('test-flag')) { }`,
42
53
  errors: [
43
54
  { messageId: 'multipleFlagCheckInExpression' },
44
55
  { messageId: 'multipleFlagCheckInExpression' },
@@ -1,17 +1,17 @@
1
1
  import type { Rule } from 'eslint';
2
+ import type { Node, Expression } from 'estree';
2
3
 
3
4
  const FF_GETTER_BOOLEAN_IDENTIFIER = 'getBooleanFF' as const;
4
5
 
5
6
  const __isOnlyOneFlagCheckInExpression = (
6
- root: Rule.Node,
7
- ignoredNode: Rule.Node,
7
+ root: Node | Expression,
8
+ ignoredNode: Node,
8
9
  ): boolean => {
9
10
  switch (root.type) {
10
11
  case 'IfStatement':
11
- return __isOnlyOneFlagCheckInExpression(
12
- root.test as Rule.Node,
13
- ignoredNode,
14
- );
12
+ return __isOnlyOneFlagCheckInExpression(root.test, ignoredNode);
13
+ case 'UnaryExpression':
14
+ return __isOnlyOneFlagCheckInExpression(root.argument, ignoredNode);
15
15
 
16
16
  case 'CallExpression':
17
17
  if (root === ignoredNode) {
@@ -29,8 +29,8 @@ const __isOnlyOneFlagCheckInExpression = (
29
29
  case 'BinaryExpression':
30
30
  case 'LogicalExpression':
31
31
  return (
32
- __isOnlyOneFlagCheckInExpression(root.left as Rule.Node, ignoredNode) &&
33
- __isOnlyOneFlagCheckInExpression(root.right as Rule.Node, ignoredNode)
32
+ __isOnlyOneFlagCheckInExpression(root.left, ignoredNode) &&
33
+ __isOnlyOneFlagCheckInExpression(root.right, ignoredNode)
34
34
  );
35
35
 
36
36
  default:
@@ -41,7 +41,8 @@ const __isOnlyOneFlagCheckInExpression = (
41
41
  const isOnlyOneFlagCheckInExpression = (node: Rule.Node): boolean => {
42
42
  let root = node.parent;
43
43
  // find the root node of the expression
44
- while (root.type === 'LogicalExpression') {
44
+ // NOTE: This is not an exhaustive check for all ESTree.Expression types but is good enough
45
+ while (root.type.endsWith('Expression')) {
45
46
  root = root.parent;
46
47
  }
47
48
 
@@ -83,6 +84,7 @@ const rule: Rule.RuleModule = {
83
84
  case 'IfStatement':
84
85
  case 'ConditionalExpression':
85
86
  break;
87
+ case 'UnaryExpression':
86
88
  case 'LogicalExpression':
87
89
  if (!isOnlyOneFlagCheckInExpression(node)) {
88
90
  context.report({