eslint-plugin-gamut 3.0.3-alpha.c94951.0 → 3.0.3-alpha.d2732e.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.
@@ -1,4 +1,4 @@
1
- eslint-plugin-gamut:build: cache hit, replaying output 16aa82dddbe273b0
1
+ eslint-plugin-gamut:build: cache hit, replaying output d0dfd7ca4be0c9cf
2
2
  eslint-plugin-gamut:build: $ yarn build:clean && yarn build:compile
3
3
  eslint-plugin-gamut:build: $ rm -rf dist
4
4
  eslint-plugin-gamut:build: $ tsc
package/CHANGELOG.md CHANGED
@@ -3,6 +3,6 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ### 3.0.3-alpha.c94951.0 (2022-02-04)
6
+ ### 3.0.3-alpha.d2732e.0 (2022-02-04)
7
7
 
8
8
  **Note:** Version bump only for package eslint-plugin-gamut
package/README.md CHANGED
@@ -1,18 +1,21 @@
1
- # `gamut-tests`
1
+ # `eslint-plugin-gamut`
2
2
 
3
- Shared component test setup for Gamut applications. ✨
4
-
5
- A wrapper around [`component-test-setup`](https://github.com/Codecademy/component-test-setup) that wraps the node with an `@emotion/react`+`gamut-styles` `<ThemeProvider theme={theme}>`.
6
- Use this instead of `component-test-setup` to test Gamut components in Gamut apps!
3
+ Recommended eslint plugin for Gamut applications. ✨
7
4
 
8
5
  ## Usage
9
6
 
10
- The API is functionally the same `component-test-setup`:
11
-
12
7
  ```tsx
13
- import { setupRtl } from '@codecademy/gamut-tests';
8
+ // eslintrc.js
9
+
10
+ module.exports = {
11
+ root: true,
14
12
 
15
- const renderView = setupRtl(MyComponent, { prop: true });
13
+ plugins: ['eslint-plugin-gamut'],
16
14
 
17
- const { view } = renderView();
15
+ rules: {
16
+ 'gamut/prefer-themed': 'error',
17
+ 'gamut/no-css-standalone': 'error',
18
+ 'gamut/import-paths': 'error',
19
+ },
20
+ };
18
21
  ```
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
4
4
  const createRule_1 = require("./createRule");
5
+ const utils_1 = require("./utils");
5
6
  exports.default = (0, createRule_1.createRule)({
6
7
  // @to-do: create helper function to get node
7
8
  create(context) {
@@ -14,29 +15,13 @@ exports.default = (0, createRule_1.createRule)({
14
15
  const arrowFuncExpression = node.quasi.expressions[0];
15
16
  if (arrowFuncExpression?.type !== experimental_utils_1.AST_NODE_TYPES.ArrowFunctionExpression)
16
17
  return;
17
- const argObject = arrowFuncExpression.params[0];
18
- if (argObject?.type !== experimental_utils_1.AST_NODE_TYPES.ObjectPattern)
18
+ if (!(0, utils_1.isNamedVariableTheme)(arrowFuncExpression))
19
19
  return;
20
- const argumentVariable = argObject.properties[0].value;
21
- if (argumentVariable?.type !== experimental_utils_1.AST_NODE_TYPES.Identifier)
22
- return;
23
- const namedArgumentVariable = argumentVariable.name;
24
- if (expressionVariable === 'styled' &&
25
- namedArgumentVariable === 'theme') {
26
- // TURN INTO UTILITY FUNCTION
27
- if (arrowFuncExpression.body.type !== experimental_utils_1.AST_NODE_TYPES.MemberExpression)
28
- return;
29
- if (arrowFuncExpression.body.object.type !==
30
- experimental_utils_1.AST_NODE_TYPES.MemberExpression)
31
- return;
32
- if (arrowFuncExpression.body.property.type !==
33
- experimental_utils_1.AST_NODE_TYPES.Identifier)
34
- return;
35
- if (arrowFuncExpression.body.object.property.type !==
36
- experimental_utils_1.AST_NODE_TYPES.Identifier)
20
+ if (expressionVariable === 'styled') {
21
+ const { themeValueKey, themeCategory } = (0, utils_1.checkArrowFuncBodyTypesAndReturnThemeVars)(arrowFuncExpression) ||
22
+ {};
23
+ if (!themeValueKey)
37
24
  return;
38
- const themeValueKey = arrowFuncExpression.body.property.name;
39
- const themeCategory = arrowFuncExpression.body.object.property.name;
40
25
  context.report({
41
26
  fix: (fixer) => {
42
27
  return fixer.replaceText(arrowFuncExpression, `themed('${themeCategory}.${themeValueKey}')`);
@@ -57,7 +42,7 @@ exports.default = (0, createRule_1.createRule)({
57
42
  },
58
43
  fixable: 'code',
59
44
  messages: {
60
- preferThemed: 'Use the themed(url) style utility instead.',
45
+ preferThemed: 'Use the themed style utility instead from gamut-styles instead.',
61
46
  },
62
47
  type: 'suggestion',
63
48
  schema: [],
@@ -1 +1 @@
1
- {"version":3,"file":"prefer-themed.js","sourceRoot":"","sources":["../src/prefer-themed.ts"],"names":[],"mappings":";;AAAA,8EAAuE;AAEvE,6CAA0C;AAE1C,kBAAe,IAAA,uBAAU,EAAC;IACxB,6CAA6C;IAE7C,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,wBAAwB,CAAC,IAAI;gBAC3B,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,mCAAc,CAAC,gBAAgB,EAAE;oBACrD,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,KAAK,YAAY;wBAAE,OAAO;oBAClD,MAAM,kBAAkB,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;oBAChD,MAAM,mBAAmB,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;oBAEtD,IACE,mBAAmB,EAAE,IAAI,KAAK,mCAAc,CAAC,uBAAuB;wBAEpE,OAAO;oBACT,MAAM,SAAS,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;oBAEhD,IAAI,SAAS,EAAE,IAAI,KAAK,mCAAc,CAAC,aAAa;wBAAE,OAAO;oBAC7D,MAAM,gBAAgB,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;oBAEvD,IAAI,gBAAgB,EAAE,IAAI,KAAK,mCAAc,CAAC,UAAU;wBAAE,OAAO;oBACjE,MAAM,qBAAqB,GAAG,gBAAgB,CAAC,IAAI,CAAC;oBAEpD,IACE,kBAAkB,KAAK,QAAQ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AO,EAAE,MAAM;QACf,QAAQ,EAAE;YACR,YAAY,EACV,iEAAiE;SACpE;QACD,IAAI,EAAE,YAAY;QAClB,MAAM,EAAE,EAAE;KACX;IACD,IAAI,EAAE,eAAe;CACtB,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { TSESTree } from '@typescript-eslint/experimental-utils';
2
+ export declare const isNamedVariableTheme: (arrowExpression: TSESTree.ArrowFunctionExpression) => boolean;
3
+ export declare const checkArrowFuncBodyTypesAndReturnThemeVars: (arrowFuncExpression: TSESTree.ArrowFunctionExpression) => false | {
4
+ themeValueKey: string;
5
+ themeCategory: string;
6
+ };
package/dist/utils.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkArrowFuncBodyTypesAndReturnThemeVars = exports.isNamedVariableTheme = void 0;
4
+ const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
5
+ const isNamedVariableTheme = (arrowExpression) => {
6
+ const argObject = arrowExpression.params[0];
7
+ if (argObject?.type !== experimental_utils_1.AST_NODE_TYPES.ObjectPattern)
8
+ return false;
9
+ const argumentVariable = argObject.properties[0].value;
10
+ if (argumentVariable?.type !== experimental_utils_1.AST_NODE_TYPES.Identifier)
11
+ return false;
12
+ const namedArgumentVariable = argumentVariable.name;
13
+ return namedArgumentVariable === 'theme';
14
+ };
15
+ exports.isNamedVariableTheme = isNamedVariableTheme;
16
+ const checkArrowFuncBodyTypesAndReturnThemeVars = (arrowFuncExpression) => {
17
+ if (arrowFuncExpression.body.type !== experimental_utils_1.AST_NODE_TYPES.MemberExpression ||
18
+ arrowFuncExpression.body.object.type !== experimental_utils_1.AST_NODE_TYPES.MemberExpression ||
19
+ arrowFuncExpression.body.property.type !== experimental_utils_1.AST_NODE_TYPES.Identifier ||
20
+ arrowFuncExpression.body.object.property.type !== experimental_utils_1.AST_NODE_TYPES.Identifier)
21
+ return false;
22
+ const themeValueKey = arrowFuncExpression.body.property.name;
23
+ const themeCategory = arrowFuncExpression.body.object.property.name;
24
+ return { themeValueKey, themeCategory };
25
+ };
26
+ exports.checkArrowFuncBodyTypesAndReturnThemeVars = checkArrowFuncBodyTypesAndReturnThemeVars;
27
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,8EAG+C;AAExC,MAAM,oBAAoB,GAAG,CAClC,eAAiD,EACjD,EAAE;IACF,MAAM,SAAS,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAE5C,IAAI,SAAS,EAAE,IAAI,KAAK,mCAAc,CAAC,aAAa;QAAE,OAAO,KAAK,CAAC;IACnE,MAAM,gBAAgB,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAEvD,IAAI,gBAAgB,EAAE,IAAI,KAAK,mCAAc,CAAC,UAAU;QAAE,OAAO,KAAK,CAAC;IACvE,MAAM,qBAAqB,GAAG,gBAAgB,CAAC,IAAI,CAAC;IAEpD,OAAO,qBAAqB,KAAK,OAAO,CAAC;AAC3C,CAAC,CAAC;AAZW,QAAA,oBAAoB,wBAY/B;AAEK,MAAM,yCAAyC,GAAG,CACvD,mBAAqD,EACrD,EAAE;IACF,IACE,mBAAmB,CAAC,IAAI,CAAC,IAAI,KAAK,mCAAc,CAAC,gBAAgB;QACjE,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,mCAAc,CAAC,gBAAgB;QACxE,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,mCAAc,CAAC,UAAU;QACpE,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,KAAK,mCAAc,CAAC,UAAU;QAE3E,OAAO,KAAK,CAAC;IAEf,MAAM,aAAa,GAAG,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC7D,MAAM,aAAa,GAAG,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;IAEpE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,CAAC;AAC1C,CAAC,CAAC;AAfW,QAAA,yCAAyC,6CAepD"}
package/jest.config.js CHANGED
@@ -1,4 +1,5 @@
1
1
  module.exports = require('../../jest.config.base')('eslint-plugin-gamut', {
2
+ testEnvironment: 'node',
2
3
  setupFiles: [],
3
4
  setupFilesAfterEnv: [],
4
5
  });
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "gamut-styles"
9
9
  ],
10
10
  "name": "eslint-plugin-gamut",
11
- "version": "3.0.3-alpha.c94951.0",
11
+ "version": "3.0.3-alpha.d2732e.0",
12
12
  "license": "MIT",
13
13
  "main": "./dist/index.js",
14
14
  "module": "dist/index.js",
@@ -35,5 +35,5 @@
35
35
  "devDependencies": {
36
36
  "@types/eslint": "^8.2.1"
37
37
  },
38
- "gitHead": "e9d19577b1b1df1ce7113d65b7ab19379608a897"
38
+ "gitHead": "ea159a99d55de6ee7592f00eb68ada77c2a25eee"
39
39
  }