eslint-plugin-gamut 3.0.3-alpha.a7c045.0 → 3.0.3-alpha.acb197.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/.turbo/turbo-build.log +4 -0
- package/CHANGELOG.md +1 -1
- package/README.md +13 -10
- package/dist/createRule.js +1 -1
- package/dist/createRule.js.map +1 -1
- package/dist/gamut-import-paths.js +8 -4
- package/dist/gamut-import-paths.js.map +1 -1
- package/dist/prefer-themed.js +7 -22
- package/dist/prefer-themed.js.map +1 -1
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +27 -0
- package/dist/utils.js.map +1 -0
- package/jest.config.js +1 -0
- package/package.json +2 -3
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.
|
|
6
|
+
### 3.0.3-alpha.acb197.0 (2022-03-17)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package eslint-plugin-gamut
|
package/README.md
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
# `gamut
|
|
1
|
+
# `eslint-plugin-gamut`
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
8
|
+
// eslintrc.js
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
root: true,
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
plugins: ['eslint-plugin-gamut'],
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
rules: {
|
|
16
|
+
'gamut/prefer-themed': 'error',
|
|
17
|
+
'gamut/no-css-standalone': 'error',
|
|
18
|
+
'gamut/import-paths': 'error',
|
|
19
|
+
},
|
|
20
|
+
};
|
|
18
21
|
```
|
package/dist/createRule.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createRule = void 0;
|
|
4
4
|
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
|
5
|
-
exports.createRule = experimental_utils_1.ESLintUtils.RuleCreator(name => `https://example.com/rule/${name}`);
|
|
5
|
+
exports.createRule = experimental_utils_1.ESLintUtils.RuleCreator((name) => `https://example.com/rule/${name}`);
|
|
6
6
|
//# sourceMappingURL=createRule.js.map
|
package/dist/createRule.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRule.js","sourceRoot":"","sources":["../src/createRule.ts"],"names":[],"mappings":";;;AAAA,8EAAoE;AAEvD,QAAA,UAAU,GAAG,gCAAW,CAAC,WAAW,CAC/C,IAAI,
|
|
1
|
+
{"version":3,"file":"createRule.js","sourceRoot":"","sources":["../src/createRule.ts"],"names":[],"mappings":";;;AAAA,8EAAoE;AAEvD,QAAA,UAAU,GAAG,gCAAW,CAAC,WAAW,CAC/C,CAAC,IAAI,EAAE,EAAE,CAAC,4BAA4B,IAAI,EAAE,CAC7C,CAAC"}
|
|
@@ -19,9 +19,11 @@ exports.default = (0, createRule_1.createRule)({
|
|
|
19
19
|
if (importPath.includes('/src')) {
|
|
20
20
|
const indexOfSrc = node.source.range[0] + importPath.search('/src');
|
|
21
21
|
context.report({
|
|
22
|
-
...(importPath.endsWith('/src') && {
|
|
22
|
+
...(importPath.endsWith('/src') && {
|
|
23
|
+
fix: (fixer) => {
|
|
23
24
|
return fixer.removeRange([indexOfSrc + 1, node.range[1] - 2]);
|
|
24
|
-
}
|
|
25
|
+
},
|
|
26
|
+
}),
|
|
25
27
|
messageId: 'removeSrc',
|
|
26
28
|
node,
|
|
27
29
|
});
|
|
@@ -30,9 +32,11 @@ exports.default = (0, createRule_1.createRule)({
|
|
|
30
32
|
if (importPath.includes('/dist')) {
|
|
31
33
|
const indexOfDist = node.source.range[0] + importPath.search('/dist');
|
|
32
34
|
context.report({
|
|
33
|
-
...(importPath.endsWith('/dist')
|
|
35
|
+
...(importPath.endsWith('/dist') && {
|
|
36
|
+
fix: (fixer) => {
|
|
34
37
|
return fixer.removeRange([indexOfDist + 1, node.range[1] - 2]);
|
|
35
|
-
}
|
|
38
|
+
},
|
|
39
|
+
}),
|
|
36
40
|
messageId: 'removeDist',
|
|
37
41
|
node,
|
|
38
42
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gamut-import-paths.js","sourceRoot":"","sources":["../src/gamut-import-paths.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"gamut-import-paths.js","sourceRoot":"","sources":["../src/gamut-import-paths.ts"],"names":[],"mappings":";;AAEA,6CAA0C;AAE1C,kBAAe,IAAA,uBAAU,EAAC;IACxB,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,gEAAgE,EAAE,UAChE,IAAgC;gBAEhC,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;gBACvC,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBAErC,MAAM,aAAa,GAAG,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;gBACpE,MAAM,aAAa,GAAG,UAAU,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;gBAExE,IAAI,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IACJ,CAAC;IACD,cAAc,EAAE,EAAE;IAClB,IAAI,EAAE;QACJ,IAAI,EAAE;YACJ,WAAW,EAAE,0DAA0D;YACvE,WAAW,EAAE,OAAO;SACrB;QACD,OAAO,EAAE,MAAM;QACf,QAAQ,EAAE;YACR,UAAU,EACR,kEAAkE;YACpE,SAAS,EACP,iEAAiE;YACnE,iBAAiB,EAAE,gDAAgD;SACpE;QACD,IAAI,EAAE,YAAY;QAClB,MAAM,EAAE,EAAE;KACX;IACD,IAAI,EAAE,oBAAoB;CAC3B,CAAC,CAAC"}
|
package/dist/prefer-themed.js
CHANGED
|
@@ -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
|
-
|
|
18
|
-
if (argObject?.type !== experimental_utils_1.AST_NODE_TYPES.ObjectPattern)
|
|
18
|
+
if (!(0, utils_1.isNamedVariableTheme)(arrowFuncExpression))
|
|
19
19
|
return;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
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;
|
|
1
|
+
{"version":3,"file":"prefer-themed.js","sourceRoot":"","sources":["../src/prefer-themed.ts"],"names":[],"mappings":";;AAAA,8EAAuE;AAEvE,6CAA0C;AAC1C,mCAGiB;AAEjB,kBAAe,IAAA,uBAAU,EAAC;IACxB,6CAA6C;IAE7C,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,wBAAwB,CAAC,IAAI;gBAC3B,IAAI,IA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,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
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.
|
|
11
|
+
"version": "3.0.3-alpha.acb197.0",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"main": "./dist/index.js",
|
|
14
14
|
"module": "dist/index.js",
|
|
@@ -28,12 +28,11 @@
|
|
|
28
28
|
},
|
|
29
29
|
"types": "./dist/index.d.ts",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@types/eslint": "^8.2.1",
|
|
32
31
|
"@typescript-eslint/experimental-utils": "^5.7.0",
|
|
33
32
|
"eslint": "^8.4.1"
|
|
34
33
|
},
|
|
35
34
|
"devDependencies": {
|
|
36
35
|
"@types/eslint": "^8.2.1"
|
|
37
36
|
},
|
|
38
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "1f2ba262bd263c1f9eb31d1beeb4d4d80ed4cb95"
|
|
39
38
|
}
|