From 5a83e4c88c00dde2df157e9d1c5a9fe7be31c138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=A9tral?= Date: Fri, 10 Mar 2023 12:50:18 +0100 Subject: [PATCH 01/18] Remove legacy eslint package We're not using it anymore, and the package moved 3 years ago: https://github.com/babel/babel-eslint/blob/b5b9a09edbac4350e4e51033a4608dd95dad1f67/README.md --- package.json | 1 - yarn.lock | 22 +++++----------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 98f332e082..2155b42bd2 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,6 @@ "@types/jest": "^29.5.0", "@types/node": "^18.15.3", "audit-ci": "^6.6.1", - "babel-eslint": "^10.0.1", "babel-jest": "^29.5.0", "babel-loader": "^9.1.2", "babel-plugin-dynamic-import-node": "^2.2.0", diff --git a/yarn.lock b/yarn.lock index af15612e55..900e8dd015 100644 --- a/yarn.lock +++ b/yarn.lock @@ -315,7 +315,7 @@ regenerator-runtime "^0.13.11" v8flags "^3.1.1" -"@babel/parser@^7.0.0", "@babel/parser@^7.1.0", "@babel/parser@^7.13.16", "@babel/parser@^7.14.7", "@babel/parser@^7.20.7", "@babel/parser@^7.21.0", "@babel/parser@^7.21.2", "@babel/parser@^7.7.0", "@babel/parser@~7.21.2": +"@babel/parser@^7.0.0", "@babel/parser@^7.1.0", "@babel/parser@^7.13.16", "@babel/parser@^7.14.7", "@babel/parser@^7.20.7", "@babel/parser@^7.21.0", "@babel/parser@^7.21.2", "@babel/parser@~7.21.2": version "7.21.2" resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.21.2.tgz#dacafadfc6d7654c3051a66d6fe55b6cb2f2a0b3" integrity sha512-URpaIJQwEkEC2T9Kn+Ai6Xe/02iNaVCuT/PtoRz3GPVJVDpPd7mLo+VddTbhCRU9TXqW5mSrQfXZyi8kDKOVpQ== @@ -1062,7 +1062,7 @@ "@babel/parser" "^7.20.7" "@babel/types" "^7.20.7" -"@babel/traverse@^7.1.6", "@babel/traverse@^7.18.11", "@babel/traverse@^7.20.7", "@babel/traverse@^7.21.0", "@babel/traverse@^7.21.2", "@babel/traverse@^7.7.0", "@babel/traverse@^7.7.2", "@babel/traverse@~7.21.2": +"@babel/traverse@^7.1.6", "@babel/traverse@^7.18.11", "@babel/traverse@^7.20.7", "@babel/traverse@^7.21.0", "@babel/traverse@^7.21.2", "@babel/traverse@^7.7.2", "@babel/traverse@~7.21.2": version "7.21.2" resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.21.2.tgz#ac7e1f27658750892e815e60ae90f382a46d8e75" integrity sha512-ts5FFU/dSUPS13tv8XiEObDu9K+iagEKME9kAbaP7r0Y9KtZJZ+NGndDvWoRAYNpeWafbpFeki3q9QoMD6gxyw== @@ -1078,7 +1078,7 @@ debug "^4.1.0" globals "^11.1.0" -"@babel/types@^7.0.0", "@babel/types@^7.18.10", "@babel/types@^7.18.6", "@babel/types@^7.18.9", "@babel/types@^7.2.0", "@babel/types@^7.20.0", "@babel/types@^7.20.2", "@babel/types@^7.20.7", "@babel/types@^7.21.0", "@babel/types@^7.21.2", "@babel/types@^7.3.0", "@babel/types@^7.3.3", "@babel/types@^7.4.4", "@babel/types@^7.7.0", "@babel/types@~7.21.2": +"@babel/types@^7.0.0", "@babel/types@^7.18.10", "@babel/types@^7.18.6", "@babel/types@^7.18.9", "@babel/types@^7.2.0", "@babel/types@^7.20.0", "@babel/types@^7.20.2", "@babel/types@^7.20.7", "@babel/types@^7.21.0", "@babel/types@^7.21.2", "@babel/types@^7.3.0", "@babel/types@^7.3.3", "@babel/types@^7.4.4", "@babel/types@~7.21.2": version "7.21.2" resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.21.2.tgz#92246f6e00f91755893c2876ad653db70c8310d1" integrity sha512-3wRZSs7jiFaB8AjxiiD+VqN5DTG2iRvJGQ+qYFrs/654lg6kGTQWIOFjlBo5RaXuAZjBmP3+OQH4dmhqiiyYxw== @@ -4967,18 +4967,6 @@ babel-core@^7.0.0-bridge.0: resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-7.0.0-bridge.0.tgz#95a492ddd90f9b4e9a4a1da14eb335b87b634ece" integrity sha512-poPX9mZH/5CSanm50Q+1toVci6pv5KSRv/5TWCwtzQS5XEwn40BcCrgIeMFWP9CKKIniKXNxoIOnOq4VVlGXhg== -babel-eslint@^10.0.1: - version "10.1.0" - resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-10.1.0.tgz#6968e568a910b78fb3779cdd8b6ac2f479943232" - integrity sha512-ifWaTHQ0ce+448CYop8AdrQiBsGrnC+bMgfyKFdi6EsPLTAWG+QfyDeM6OH+FmWnKvEq5NnBMLvlBUPKQZoDSg== - dependencies: - "@babel/code-frame" "^7.0.0" - "@babel/parser" "^7.7.0" - "@babel/traverse" "^7.7.0" - "@babel/types" "^7.7.0" - eslint-visitor-keys "^1.0.0" - resolve "^1.12.0" - babel-jest@^29.5.0: version "29.5.0" resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-29.5.0.tgz#3fe3ddb109198e78b1c88f9ebdecd5e4fc2f50a5" @@ -7459,7 +7447,7 @@ eslint-utils@^3.0.0: dependencies: eslint-visitor-keys "^2.0.0" -eslint-visitor-keys@^1.0.0, eslint-visitor-keys@^1.1.0: +eslint-visitor-keys@^1.1.0: version "1.3.0" resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz#30ebd1ef7c2fdff01c3a4f151044af25fab0523e" integrity sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ== @@ -14137,7 +14125,7 @@ resolve.exports@^2.0.0: resolved "https://registry.yarnpkg.com/resolve.exports/-/resolve.exports-2.0.0.tgz#c1a0028c2d166ec2fbf7d0644584927e76e7400e" integrity sha512-6K/gDlqgQscOlg9fSRpWstA8sYe8rbELsSTNpx+3kTrsVCzvSl0zIvRErM7fdl9ERWDsKnrLnwB+Ne89918XOg== -resolve@^1.0.0, resolve@^1.1.6, resolve@^1.10.0, resolve@^1.10.1, resolve@^1.12.0, resolve@^1.14.2, resolve@^1.19.0, resolve@^1.20.0, resolve@^1.22.0, resolve@^1.22.1: +resolve@^1.0.0, resolve@^1.1.6, resolve@^1.10.0, resolve@^1.10.1, resolve@^1.14.2, resolve@^1.19.0, resolve@^1.20.0, resolve@^1.22.0, resolve@^1.22.1: version "1.22.1" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.1.tgz#27cb2ebb53f91abb49470a928bba7558066ac177" integrity sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw== From bac1d16f6ddeb7d05d8083c5cfe6af93093bcacc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=A9tral?= Date: Mon, 13 Mar 2023 08:54:08 +0100 Subject: [PATCH 02/18] Add draft TypeScript ESLint plugin The rule is still a WIP and will currently error on a single valid property. The config should work, so this commit should fail in CI. Draft docs are written, no tests yet. --- .eslintignore | 2 - .eslintrc.js | 4 + .prettierignore | 1 - package.json | 1 + packages/eslint-plugin/LICENSE | 201 ++++++++++++++++++ packages/eslint-plugin/README.md | 44 ++++ packages/eslint-plugin/index.ts | 20 ++ .../no-invalid-custom-properties/README.md | 31 +++ .../index.spec.ts | 16 ++ .../no-invalid-custom-properties/index.ts | 74 +++++++ packages/eslint-plugin/package.json | 32 +++ packages/eslint-plugin/tsconfig.json | 4 + yarn.lock | 55 ++++- 13 files changed, 481 insertions(+), 4 deletions(-) create mode 100644 packages/eslint-plugin/LICENSE create mode 100644 packages/eslint-plugin/README.md create mode 100644 packages/eslint-plugin/index.ts create mode 100644 packages/eslint-plugin/no-invalid-custom-properties/README.md create mode 100644 packages/eslint-plugin/no-invalid-custom-properties/index.spec.ts create mode 100644 packages/eslint-plugin/no-invalid-custom-properties/index.ts create mode 100644 packages/eslint-plugin/package.json create mode 100644 packages/eslint-plugin/tsconfig.json diff --git a/.eslintignore b/.eslintignore index e2c12c95c2..c005837ab9 100644 --- a/.eslintignore +++ b/.eslintignore @@ -10,8 +10,6 @@ __reports__/ *.config.js *rc.js jest.*.js -tsconfig.json -package.json scripts/ # disable linting for the template because it will have its own rules when used in a new app packages/cna-template/template diff --git a/.eslintrc.js b/.eslintrc.js index 596a7590b2..c5ec68db30 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,4 +1,8 @@ module.exports = require('@sumup/foundry/eslint')({ + plugins: ['@sumup'], + rules: { + '@sumup/no-invalid-custom-properties': 'error', + }, parserOptions: { project: ['./packages/*/tsconfig.json', './tsconfig.eslint.json'], tsconfigRootDir: __dirname, diff --git a/.prettierignore b/.prettierignore index 140844cac0..c2658d7d1b 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,2 +1 @@ node_modules/ -package.json diff --git a/package.json b/package.json index 2155b42bd2..1cd6552ec5 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "@storybook/source-loader": "^7.0.0-beta.60", "@storybook/testing-library": "^0.0.14-next.1", "@storybook/theming": "^7.0.0-beta.60", + "@sumup/eslint-plugin": "^1.0.0", "@sumup/foundry": "^5.1.0", "@types/jest": "^29.5.0", "@types/node": "^18.15.3", diff --git a/packages/eslint-plugin/LICENSE b/packages/eslint-plugin/LICENSE new file mode 100644 index 0000000000..adda489814 --- /dev/null +++ b/packages/eslint-plugin/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright 2019 SumUp Ltd. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md new file mode 100644 index 0000000000..6b9653cf52 --- /dev/null +++ b/packages/eslint-plugin/README.md @@ -0,0 +1,44 @@ +
+ +# @sumup/eslint-plugin + +ESLint rules to lint Circuit UI. + +[![Stars](https://img.shields.io/github/stars/sumup-oss/circuit-ui?style=social)](https://github.com/sumup-oss/circuit-ui/) [![Version](https://img.shields.io/npm/v/@sumup/design-tokens)](https://www.npmjs.com/package/@sumup/design-tokens) [![Coverage](https://img.shields.io/codecov/c/github/sumup-oss/circuit-ui)](https://codecov.io/gh/sumup-oss/circuit-ui) [![License](https://img.shields.io/badge/license--lightgrey.svg)](https://github.com/sumup-oss/circuit-ui/tree/main/packages/design-tokens/LICENSE) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.1%20adopted-ff69b4.svg)](https://github.com/sumup-oss/circuit-ui/tree/main/CODE_OF_CONDUCT.md) + +
+ +## Installation + +Depending on your preference, run one of the following in your terminal: + +```sh +# With Yarn +yarn add @sumup/design-tokens +# With npm +npm install @sumup/design-tokens +``` + +## Usage + +Add the plugin to your [ESLint configuration file](https://eslint.org/docs/latest/use/configure/configuration-files): + +```json +{ + "plugins": ["@sumup"] +} +``` + +Rules are configured under the rules section: + +```json +{ + "rules": { + "@sumup/": "error" + } +} +``` + +## Supported Rules + +- [`no-invalid-custom-properties`](./no-invalid-custom-properties/) diff --git a/packages/eslint-plugin/index.ts b/packages/eslint-plugin/index.ts new file mode 100644 index 0000000000..c70bf79961 --- /dev/null +++ b/packages/eslint-plugin/index.ts @@ -0,0 +1,20 @@ +/** + * Copyright 2023, SumUp Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { noInvalidCustomProperties } from './no-invalid-custom-properties'; + +export const rules = { + 'no-invalid-custom-properties': noInvalidCustomProperties, +}; diff --git a/packages/eslint-plugin/no-invalid-custom-properties/README.md b/packages/eslint-plugin/no-invalid-custom-properties/README.md new file mode 100644 index 0000000000..d0aecb9f29 --- /dev/null +++ b/packages/eslint-plugin/no-invalid-custom-properties/README.md @@ -0,0 +1,31 @@ +# Do not invalid Circuit UI custom properties (`no-invalid-custom-properties`) + +Circuit UI exports a number of CSS custom properties (a.k.a. CSS variables) prefixed with `--cui`. This rule checks that custom properties using that prefix are valid. + +## Rule Details + +This rule aims to prevent issues when using custom properties. In contrast to the legacy JSON theme in `@sumup/design-tokens`, IDEs and CIs will _not_ warn or error by default if using an invalid property. Setting its error level to `error` (or `2`) is recommended. + +Examples of **incorrect** code for this rule: + +```css +color: var(--cui-invalid-property); +``` + +Examples of **correct** code for this rule: + +```js +color: var(--cui-bg-normal); +``` + +### Options + +n/a + +## When Not To Use It + +n/a + +## Further Reading + +- [Theme documentation](https://circuit.sumup.com/?path=/docs/features-theme--docs) on the Circuit UI docs diff --git a/packages/eslint-plugin/no-invalid-custom-properties/index.spec.ts b/packages/eslint-plugin/no-invalid-custom-properties/index.spec.ts new file mode 100644 index 0000000000..5a6a1058c5 --- /dev/null +++ b/packages/eslint-plugin/no-invalid-custom-properties/index.spec.ts @@ -0,0 +1,16 @@ +/** + * Copyright 2023, SumUp Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TODO diff --git a/packages/eslint-plugin/no-invalid-custom-properties/index.ts b/packages/eslint-plugin/no-invalid-custom-properties/index.ts new file mode 100644 index 0000000000..b70bb40717 --- /dev/null +++ b/packages/eslint-plugin/no-invalid-custom-properties/index.ts @@ -0,0 +1,74 @@ +/** + * Copyright 2023, SumUp Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ESLintUtils } from '@typescript-eslint/utils'; + +/** + * TODO. For now this is to see whether the rule runs (it should error on all + * occurrences of the --cui-fg-success string). + */ +const REGEX = /--cui-fg-success/g; + +const createRule = ESLintUtils.RuleCreator( + (name) => `https://github.com/TODO/${name}`, +); + +export const noInvalidCustomProperties = createRule({ + name: 'no-invalid-custom-properties', + meta: { + type: 'problem', + schema: [], + docs: { + description: + 'Custom properties prefixed in `--cui` should be valid Circuit UI color tokens.', + recommended: 'error', + }, + messages: { + invalid: '"{{name}}" is not a valid Circuit UI color token.', + }, + }, + defaultOptions: [], + create(context) { + const sourceCode = context.getSourceCode(); + return { + // Inspired by `no-tabs`: https://github.com/eslint/eslint/blob/b98fdd413a3b07b262bfce6f704c1c1bb8582770/lib/rules/no-tabs.js + Program(node) { + sourceCode.getLines().forEach((line, index) => { + let match; + // eslint-disable-next-line no-cond-assign + while ((match = REGEX.exec(line)) !== null) { + context.report({ + node, + loc: { + start: { + line: index + 1, + column: match.index, + }, + end: { + line: index + 1, + column: match.index + match[0].length, + }, + }, + messageId: 'invalid', + data: { + name: match[0], + }, + }); + } + }); + }, + }; + }, +}); diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json new file mode 100644 index 0000000000..aa18ff9bea --- /dev/null +++ b/packages/eslint-plugin/package.json @@ -0,0 +1,32 @@ +{ + "name": "@sumup/eslint-plugin", + "version": "1.0.0", + "description": "ESLint rules to lint Circuit UI.", + "main": "dist/index.js", + "files": [ + "dist", + "package.json", + "README.md", + "LICENSE" + ], + "repository": { + "type": "git", + "directory": "packages/eslint-plugin", + "url": "git+https://github.com/sumup-oss/circuit-ui.git" + }, + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/sumup-oss/circuit-ui/issues" + }, + "homepage": "https://github.com/sumup-oss/circuit-ui/tree/main/packages/eslint-plugin/README.md", + "scripts": { + "build": "tsc" + }, + "dependencies": { + "@typescript-eslint/utils": "^5.54.1" + }, + "devDependencies": { + "@tsconfig/node18": "^1.0.1", + "typescript": "^4.9.5" + } +} diff --git a/packages/eslint-plugin/tsconfig.json b/packages/eslint-plugin/tsconfig.json new file mode 100644 index 0000000000..8ab282174c --- /dev/null +++ b/packages/eslint-plugin/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "@tsconfig/node18/tsconfig.json", + "compilerOptions": { "outDir": "dist" } +} diff --git a/yarn.lock b/yarn.lock index 900e8dd015..9edd2d4b53 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3714,6 +3714,11 @@ resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.2.tgz#423c77877d0569db20e1fc80885ac4118314010e" integrity sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA== +"@tsconfig/node18@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@tsconfig/node18/-/node18-1.0.1.tgz#ea5b375a9ead6b09ccbd70c3894ea069829ea1bb" + integrity sha512-sNFeK6X2ATlhlvzyH4kKYQlfHXE2f2/wxtB9ClvYXevWpmwkUT7VaSrjIN9E76Qebz8qP5JOJJ9jD3QoD/Z9TA== + "@types/aria-query@^5.0.1": version "5.0.1" resolved "https://registry.yarnpkg.com/@types/aria-query/-/aria-query-5.0.1.tgz#3286741fb8f1e1580ac28784add4c7a1d49bdfbc" @@ -4095,7 +4100,7 @@ resolved "https://registry.yarnpkg.com/@types/semver/-/semver-6.2.2.tgz#5c27df09ca39e3c9beb4fae6b95f4d71426df0a9" integrity sha512-RxAwYt4rGwK5GyoRwuP0jT6ZHAVTdz2EqgsHmX0PYNjGsko+OeT4WFXXTs/lM3teJUJodM+SNtAL5/pXIJ61IQ== -"@types/semver@^7.3.4": +"@types/semver@^7.3.12", "@types/semver@^7.3.4": version "7.3.13" resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.13.tgz#da4bfd73f49bd541d28920ab0e2bf0ee80f71c91" integrity sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw== @@ -4192,6 +4197,14 @@ "@typescript-eslint/types" "5.30.5" "@typescript-eslint/visitor-keys" "5.30.5" +"@typescript-eslint/scope-manager@5.54.1": + version "5.54.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.54.1.tgz#6d864b4915741c608a58ce9912edf5a02bb58735" + integrity sha512-zWKuGliXxvuxyM71UA/EcPxaviw39dB2504LqAmFDjmkpO8qNLHcmzlh6pbHs1h/7YQ9bnsO8CCcYCSA8sykUg== + dependencies: + "@typescript-eslint/types" "5.54.1" + "@typescript-eslint/visitor-keys" "5.54.1" + "@typescript-eslint/type-utils@5.30.5": version "5.30.5" resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.30.5.tgz#7a9656f360b4b1daea635c4621dab053d08bf8a9" @@ -4206,6 +4219,11 @@ resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.30.5.tgz#36a0c05a72af3623cdf9ee8b81ea743b7de75a98" integrity sha512-kZ80w/M2AvsbRvOr3PjaNh6qEW1LFqs2pLdo2s5R38B2HYXG8Z0PP48/4+j1QHJFL3ssHIbJ4odPRS8PlHrFfw== +"@typescript-eslint/types@5.54.1": + version "5.54.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.54.1.tgz#29fbac29a716d0f08c62fe5de70c9b6735de215c" + integrity sha512-G9+1vVazrfAfbtmCapJX8jRo2E4MDXxgm/IMOF4oGh3kq7XuK3JRkOg6y2Qu1VsTRmWETyTkWt1wxy7X7/yLkw== + "@typescript-eslint/typescript-estree@5.30.5": version "5.30.5" resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.30.5.tgz#c520e4eba20551c4ec76af8d344a42eb6c9767bb" @@ -4219,6 +4237,19 @@ semver "^7.3.7" tsutils "^3.21.0" +"@typescript-eslint/typescript-estree@5.54.1": + version "5.54.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.54.1.tgz#df7b6ae05fd8fef724a87afa7e2f57fa4a599be1" + integrity sha512-bjK5t+S6ffHnVwA0qRPTZrxKSaFYocwFIkZx5k7pvWfsB1I57pO/0M0Skatzzw1sCkjJ83AfGTL0oFIFiDX3bg== + dependencies: + "@typescript-eslint/types" "5.54.1" + "@typescript-eslint/visitor-keys" "5.54.1" + debug "^4.3.4" + globby "^11.1.0" + is-glob "^4.0.3" + semver "^7.3.7" + tsutils "^3.21.0" + "@typescript-eslint/utils@5.30.5", "@typescript-eslint/utils@^5.10.0", "@typescript-eslint/utils@^5.13.0": version "5.30.5" resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.30.5.tgz#3999cbd06baad31b9e60d084f20714d1b2776765" @@ -4231,6 +4262,20 @@ eslint-scope "^5.1.1" eslint-utils "^3.0.0" +"@typescript-eslint/utils@^5.54.1": + version "5.54.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.54.1.tgz#7a3ee47409285387b9d4609ea7e1020d1797ec34" + integrity sha512-IY5dyQM8XD1zfDe5X8jegX6r2EVU5o/WJnLu/znLPWCBF7KNGC+adacXnt5jEYS9JixDcoccI6CvE4RCjHMzCQ== + dependencies: + "@types/json-schema" "^7.0.9" + "@types/semver" "^7.3.12" + "@typescript-eslint/scope-manager" "5.54.1" + "@typescript-eslint/types" "5.54.1" + "@typescript-eslint/typescript-estree" "5.54.1" + eslint-scope "^5.1.1" + eslint-utils "^3.0.0" + semver "^7.3.7" + "@typescript-eslint/visitor-keys@5.30.5": version "5.30.5" resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.30.5.tgz#d4bb969202019d5d5d849a0aaedc7370cc044b14" @@ -4239,6 +4284,14 @@ "@typescript-eslint/types" "5.30.5" eslint-visitor-keys "^3.3.0" +"@typescript-eslint/visitor-keys@5.54.1": + version "5.54.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.54.1.tgz#d7a8a0f7181d6ac748f4d47b2306e0513b98bf8b" + integrity sha512-q8iSoHTgwCfgcRJ2l2x+xCbu8nBlRAlsQ33k24Adj8eoVBE0f8dUeI+bAa8F84Mv05UGbAx57g2zrRsYIooqQg== + dependencies: + "@typescript-eslint/types" "5.54.1" + eslint-visitor-keys "^3.3.0" + "@webassemblyjs/ast@1.11.1": version "1.11.1" resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.1.tgz#2bfd767eae1a6996f432ff7e8d7fc75679c0b6a7" From e88f26419f5f68eebe446cf8b55977ee715a41d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=A9tral?= Date: Tue, 14 Mar 2023 13:56:20 +0100 Subject: [PATCH 03/18] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Connor Bär --- packages/eslint-plugin/no-invalid-custom-properties/README.md | 2 +- packages/eslint-plugin/no-invalid-custom-properties/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-plugin/no-invalid-custom-properties/README.md b/packages/eslint-plugin/no-invalid-custom-properties/README.md index d0aecb9f29..6fffb9ccd5 100644 --- a/packages/eslint-plugin/no-invalid-custom-properties/README.md +++ b/packages/eslint-plugin/no-invalid-custom-properties/README.md @@ -1,4 +1,4 @@ -# Do not invalid Circuit UI custom properties (`no-invalid-custom-properties`) +# Do not use invalid Circuit UI custom properties (`no-invalid-custom-properties`) Circuit UI exports a number of CSS custom properties (a.k.a. CSS variables) prefixed with `--cui`. This rule checks that custom properties using that prefix are valid. diff --git a/packages/eslint-plugin/no-invalid-custom-properties/index.ts b/packages/eslint-plugin/no-invalid-custom-properties/index.ts index b70bb40717..eb79d501f8 100644 --- a/packages/eslint-plugin/no-invalid-custom-properties/index.ts +++ b/packages/eslint-plugin/no-invalid-custom-properties/index.ts @@ -32,7 +32,7 @@ export const noInvalidCustomProperties = createRule({ schema: [], docs: { description: - 'Custom properties prefixed in `--cui` should be valid Circuit UI color tokens.', + 'Custom properties prefixed with `--cui` should be valid Circuit UI color tokens.', recommended: 'error', }, messages: { From a93bba48e51c95d852bf510e7fe4b8b4bc04cf9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=A9tral?= Date: Tue, 14 Mar 2023 14:03:45 +0100 Subject: [PATCH 04/18] Rename eslint plugin --- .eslintrc.js | 4 +- package.json | 2 +- .../LICENSE | 0 packages/eslint-plugin-circuit-ui/README.md | 44 +++++++++++++++++++ .../index.ts | 0 .../no-invalid-custom-properties/README.md | 0 .../index.spec.ts | 0 .../no-invalid-custom-properties/index.ts | 0 .../package.json | 6 +-- .../tsconfig.json | 0 packages/eslint-plugin/README.md | 44 ------------------- 11 files changed, 50 insertions(+), 50 deletions(-) rename packages/{eslint-plugin => eslint-plugin-circuit-ui}/LICENSE (100%) create mode 100644 packages/eslint-plugin-circuit-ui/README.md rename packages/{eslint-plugin => eslint-plugin-circuit-ui}/index.ts (100%) rename packages/{eslint-plugin => eslint-plugin-circuit-ui}/no-invalid-custom-properties/README.md (100%) rename packages/{eslint-plugin => eslint-plugin-circuit-ui}/no-invalid-custom-properties/index.spec.ts (100%) rename packages/{eslint-plugin => eslint-plugin-circuit-ui}/no-invalid-custom-properties/index.ts (100%) rename packages/{eslint-plugin => eslint-plugin-circuit-ui}/package.json (81%) rename packages/{eslint-plugin => eslint-plugin-circuit-ui}/tsconfig.json (100%) delete mode 100644 packages/eslint-plugin/README.md diff --git a/.eslintrc.js b/.eslintrc.js index c5ec68db30..da11bb20ec 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = require('@sumup/foundry/eslint')({ - plugins: ['@sumup'], + plugins: ['@sumup/circuit-ui'], rules: { - '@sumup/no-invalid-custom-properties': 'error', + '@sumup/circuit-ui/no-invalid-custom-properties': 'error', }, parserOptions: { project: ['./packages/*/tsconfig.json', './tsconfig.eslint.json'], diff --git a/package.json b/package.json index 1cd6552ec5..94afb44a52 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "@storybook/source-loader": "^7.0.0-beta.60", "@storybook/testing-library": "^0.0.14-next.1", "@storybook/theming": "^7.0.0-beta.60", - "@sumup/eslint-plugin": "^1.0.0", + "@sumup/eslint-plugin-circuit-ui": "^1.0.0", "@sumup/foundry": "^5.1.0", "@types/jest": "^29.5.0", "@types/node": "^18.15.3", diff --git a/packages/eslint-plugin/LICENSE b/packages/eslint-plugin-circuit-ui/LICENSE similarity index 100% rename from packages/eslint-plugin/LICENSE rename to packages/eslint-plugin-circuit-ui/LICENSE diff --git a/packages/eslint-plugin-circuit-ui/README.md b/packages/eslint-plugin-circuit-ui/README.md new file mode 100644 index 0000000000..0e7e98356a --- /dev/null +++ b/packages/eslint-plugin-circuit-ui/README.md @@ -0,0 +1,44 @@ +
+ +# @sumup/eslint-plugin-circuit-ui + +ESLint rules to lint Circuit UI. + +[![Stars](https://img.shields.io/github/stars/sumup-oss/circuit-ui?style=social)](https://github.com/sumup-oss/circuit-ui/) [![Version](https://img.shields.io/npm/v/@sumup/eslint-plugin-circuit-ui)](https://www.npmjs.com/package/@sumup/eslint-plugin-circuit-ui) [![Coverage](https://img.shields.io/codecov/c/github/sumup-oss/circuit-ui)](https://codecov.io/gh/sumup-oss/circuit-ui) [![License](https://img.shields.io/badge/license--lightgrey.svg)](https://github.com/sumup-oss/circuit-ui/tree/main/packages/eslint-plugin-circuit-ui/LICENSE) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.1%20adopted-ff69b4.svg)](https://github.com/sumup-oss/circuit-ui/tree/main/CODE_OF_CONDUCT.md) + +
+ +## Installation + +Depending on your preference, run one of the following in your terminal: + +```sh +# With Yarn +yarn add @sumup/eslint-plugin-circuit-ui +# With npm +npm install @sumup/eslint-plugin-circuit-ui +``` + +## Usage + +Add the plugin to your [ESLint configuration file](https://eslint.org/docs/latest/use/configure/configuration-files): + +```json +{ + "plugins": ["@sumup/circuit-ui"] +} +``` + +Rules are configured under the rules section: + +```json +{ + "rules": { + "@sumup/": "error" + } +} +``` + +## Supported Rules + +- [`no-invalid-custom-properties`](./no-invalid-custom-properties/) diff --git a/packages/eslint-plugin/index.ts b/packages/eslint-plugin-circuit-ui/index.ts similarity index 100% rename from packages/eslint-plugin/index.ts rename to packages/eslint-plugin-circuit-ui/index.ts diff --git a/packages/eslint-plugin/no-invalid-custom-properties/README.md b/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/README.md similarity index 100% rename from packages/eslint-plugin/no-invalid-custom-properties/README.md rename to packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/README.md diff --git a/packages/eslint-plugin/no-invalid-custom-properties/index.spec.ts b/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.spec.ts similarity index 100% rename from packages/eslint-plugin/no-invalid-custom-properties/index.spec.ts rename to packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.spec.ts diff --git a/packages/eslint-plugin/no-invalid-custom-properties/index.ts b/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.ts similarity index 100% rename from packages/eslint-plugin/no-invalid-custom-properties/index.ts rename to packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.ts diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin-circuit-ui/package.json similarity index 81% rename from packages/eslint-plugin/package.json rename to packages/eslint-plugin-circuit-ui/package.json index aa18ff9bea..2fa1058210 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin-circuit-ui/package.json @@ -1,5 +1,5 @@ { - "name": "@sumup/eslint-plugin", + "name": "@sumup/eslint-plugin-circuit-ui", "version": "1.0.0", "description": "ESLint rules to lint Circuit UI.", "main": "dist/index.js", @@ -11,14 +11,14 @@ ], "repository": { "type": "git", - "directory": "packages/eslint-plugin", + "directory": "packages/eslint-plugin-circuit-ui", "url": "git+https://github.com/sumup-oss/circuit-ui.git" }, "license": "Apache-2.0", "bugs": { "url": "https://github.com/sumup-oss/circuit-ui/issues" }, - "homepage": "https://github.com/sumup-oss/circuit-ui/tree/main/packages/eslint-plugin/README.md", + "homepage": "https://github.com/sumup-oss/circuit-ui/tree/main/packages/eslint-plugin-circuit-ui/README.md", "scripts": { "build": "tsc" }, diff --git a/packages/eslint-plugin/tsconfig.json b/packages/eslint-plugin-circuit-ui/tsconfig.json similarity index 100% rename from packages/eslint-plugin/tsconfig.json rename to packages/eslint-plugin-circuit-ui/tsconfig.json diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md deleted file mode 100644 index 6b9653cf52..0000000000 --- a/packages/eslint-plugin/README.md +++ /dev/null @@ -1,44 +0,0 @@ -
- -# @sumup/eslint-plugin - -ESLint rules to lint Circuit UI. - -[![Stars](https://img.shields.io/github/stars/sumup-oss/circuit-ui?style=social)](https://github.com/sumup-oss/circuit-ui/) [![Version](https://img.shields.io/npm/v/@sumup/design-tokens)](https://www.npmjs.com/package/@sumup/design-tokens) [![Coverage](https://img.shields.io/codecov/c/github/sumup-oss/circuit-ui)](https://codecov.io/gh/sumup-oss/circuit-ui) [![License](https://img.shields.io/badge/license--lightgrey.svg)](https://github.com/sumup-oss/circuit-ui/tree/main/packages/design-tokens/LICENSE) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.1%20adopted-ff69b4.svg)](https://github.com/sumup-oss/circuit-ui/tree/main/CODE_OF_CONDUCT.md) - -
- -## Installation - -Depending on your preference, run one of the following in your terminal: - -```sh -# With Yarn -yarn add @sumup/design-tokens -# With npm -npm install @sumup/design-tokens -``` - -## Usage - -Add the plugin to your [ESLint configuration file](https://eslint.org/docs/latest/use/configure/configuration-files): - -```json -{ - "plugins": ["@sumup"] -} -``` - -Rules are configured under the rules section: - -```json -{ - "rules": { - "@sumup/": "error" - } -} -``` - -## Supported Rules - -- [`no-invalid-custom-properties`](./no-invalid-custom-properties/) From 493acdb17235212e06a7ba6f338176e4aa8dd95d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=A9tral?= Date: Tue, 14 Mar 2023 14:04:55 +0100 Subject: [PATCH 05/18] Fix eslint plugin README --- packages/eslint-plugin-circuit-ui/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin-circuit-ui/README.md b/packages/eslint-plugin-circuit-ui/README.md index 0e7e98356a..25d9d3c6be 100644 --- a/packages/eslint-plugin-circuit-ui/README.md +++ b/packages/eslint-plugin-circuit-ui/README.md @@ -34,7 +34,7 @@ Rules are configured under the rules section: ```json { "rules": { - "@sumup/": "error" + "@sumup/circuit-ui/": "error" } } ``` From e0e873624cb21d4db552eaec15d91488b2b5edd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=A9tral?= Date: Tue, 14 Mar 2023 19:08:10 +0100 Subject: [PATCH 06/18] Write draft matcher This purposefully still includes the debugging RegExp I used. Will clean up later on. --- .../no-invalid-custom-properties/index.ts | 168 +++++++++++++++++- 1 file changed, 162 insertions(+), 6 deletions(-) diff --git a/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.ts b/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.ts index eb79d501f8..103628e11b 100644 --- a/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.ts +++ b/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.ts @@ -15,14 +15,170 @@ import { ESLintUtils } from '@typescript-eslint/utils'; -/** - * TODO. For now this is to see whether the rule runs (it should error on all - * occurrences of the --cui-fg-success string). - */ -const REGEX = /--cui-fg-success/g; +const VALID_CUSTOM_PROPERTIES_WITHOUT_PREFIX = [ + /* Neutral backgrounds */ + 'bg-normal', + 'bg-normal-hovered', + 'bg-normal-pressed', + 'bg-normal-disabled', + 'bg-subtle', + 'bg-subtle-hovered', + 'bg-subtle-pressed', + 'bg-subtle-disabled', + 'bg-highlight', + 'bg-highlight-hovered', + 'bg-highlight-pressed', + 'bg-highlight-disabled', + 'bg-strong', + 'bg-strong-hovered', + 'bg-strong-pressed', + 'bg-strong-disabled', + /* Accent backgrounds */ + 'bg-accent', + 'bg-accent-hovered', + 'bg-accent-pressed', + 'bg-accent-disabled', + 'bg-accent-strong', + 'bg-accent-strong-hovered', + 'bg-accent-strong-pressed', + 'bg-accent-strong-disabled', + /* Success backgrounds */ + 'bg-success', + 'bg-success-hovered', + 'bg-success-pressed', + 'bg-success-disabled', + 'bg-success-strong', + 'bg-success-strong-hovered', + 'bg-success-strong-pressed', + 'bg-success-strong-disabled', + /* Warning backgrounds */ + 'bg-warning', + 'bg-warning-hovered', + 'bg-warning-pressed', + 'bg-warning-disabled', + 'bg-warning-strong', + 'bg-warning-strong-hovered', + 'bg-warning-strong-pressed', + 'bg-warning-strong-disabled', + /* Danger backgrounds */ + 'bg-danger', + 'bg-danger-hovered', + 'bg-danger-pressed', + 'bg-danger-disabled', + 'bg-danger-strong', + 'bg-danger-strong-hovered', + 'bg-danger-strong-pressed', + 'bg-danger-strong-disabled', + /* Promo backgrounds */ + 'bg-promo', + 'bg-promo-hovered', + 'bg-promo-pressed', + 'bg-promo-disabled', + 'bg-promo-strong', + 'bg-promo-strong-hovered', + 'bg-promo-strong-pressed', + 'bg-promo-strong-disabled', + /* Neutral foregrounds */ + 'fg-normal', + 'fg-normal-hovered', + 'fg-normal-pressed', + 'fg-normal-disabled', + 'fg-subtle', + 'fg-subtle-hovered', + 'fg-subtle-pressed', + 'fg-subtle-disabled', + 'fg-placeholder', + 'fg-placeholder-hovered', + 'fg-placeholder-pressed', + 'fg-placeholder-disabled', + 'fg-on-strong', + 'fg-on-strong-hovered', + 'fg-on-strong-pressed', + 'fg-on-strong-disabled', + /* Accent foregrounds */ + 'fg-accent', + 'fg-accent-hovered', + 'fg-accent-pressed', + 'fg-accent-disabled', + /* Success foregrounds */ + 'fg-success', + 'fg-success-hovered', + 'fg-success-pressed', + 'fg-success-disabled', + /* Warning foregrounds */ + 'fg-warning', + 'fg-warning-hovered', + 'fg-warning-pressed', + 'fg-warning-disabled', + /* Danger foregrounds */ + 'fg-danger', + 'fg-danger-hovered', + 'fg-danger-pressed', + 'fg-danger-disabled', + /* Promo foregrounds */ + 'fg-promo', + 'fg-promo-hovered', + 'fg-promo-pressed', + 'fg-promo-disabled', + /* Neutral borders */ + 'border-normal', + 'border-normal-hovered', + 'border-normal-pressed', + 'border-normal-disabled', + 'border-subtle', + 'border-subtle-hovered', + 'border-subtle-pressed', + 'border-subtle-disabled', + 'border-divider', + 'border-divider-hovered', + 'border-divider-pressed', + 'border-divider-disabled', + 'border-strong', + 'border-strong-hovered', + 'border-strong-pressed', + 'border-strong-disabled', + /* Accent borders */ + 'border-accent', + 'border-accent-hovered', + 'border-accent-pressed', + 'border-accent-disabled', + /* Success borders */ + 'border-success', + 'border-success-hovered', + 'border-success-pressed', + 'border-success-disabled', + /* Warning borders */ + 'border-warning', + 'border-warning-hovered', + 'border-warning-pressed', + 'border-warning-disabled', + /* Danger borders */ + 'border-danger', + 'border-danger-hovered', + 'border-danger-pressed', + 'border-danger-disabled', + /* Promo borders */ + 'border-promo', + 'border-promo-hovered', + 'border-promo-pressed', + 'border-promo-disabled', + /* Special colors */ + 'bg-overlay', + 'bg-elevated', + 'border-focus', +]; + +/* eslint-disable no-useless-escape, @typescript-eslint/quotes */ +const REGEX_STRING = `(?:--cui-)(?!(?:${VALID_CUSTOM_PROPERTIES_WITHOUT_PREFIX.join( + '|', +)})[^\w\-])[a-zA-Z0-9\-]+`; +const REGEX_DEBUG = `(?:--cui-)(?!(?:fg-normal|bg-normal)[^\w\-])[a-zA-Z0-9\-]+`; +/* eslint-enable no-useless-escape, @typescript-eslint/quotes */ +const REGEX = new RegExp(REGEX_STRING, 'g'); const createRule = ESLintUtils.RuleCreator( - (name) => `https://github.com/TODO/${name}`, + (name) => + `https://github.com/sumup-oss/circuit-ui/tree/main/packages/eslint-plugin-circuit-ui/${name}`, ); export const noInvalidCustomProperties = createRule({ From 992e190bb0fc576a36a06a6db38c60b7a5753a3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=A9tral?= Date: Wed, 15 Mar 2023 16:07:32 +0100 Subject: [PATCH 07/18] Remove useless escape --- .../no-invalid-custom-properties/index.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.ts b/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.ts index 103628e11b..0735e172d9 100644 --- a/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.ts +++ b/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.ts @@ -168,12 +168,11 @@ const VALID_CUSTOM_PROPERTIES_WITHOUT_PREFIX = [ 'border-focus', ]; -/* eslint-disable no-useless-escape, @typescript-eslint/quotes */ +/* eslint-disable no-useless-escape */ const REGEX_STRING = `(?:--cui-)(?!(?:${VALID_CUSTOM_PROPERTIES_WITHOUT_PREFIX.join( '|', -)})[^\w\-])[a-zA-Z0-9\-]+`; -const REGEX_DEBUG = `(?:--cui-)(?!(?:fg-normal|bg-normal)[^\w\-])[a-zA-Z0-9\-]+`; -/* eslint-enable no-useless-escape, @typescript-eslint/quotes */ +)})[^\w-])[a-zA-Z0-9-]+`; +/* eslint-enable no-useless-escape */ const REGEX = new RegExp(REGEX_STRING, 'g'); const createRule = ESLintUtils.RuleCreator( From 32ae64bbc57565769051ea05b10ebeb82d9d7365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=A9tral?= Date: Wed, 15 Mar 2023 17:29:54 +0100 Subject: [PATCH 08/18] Add wip test setup This surfaced a bug with the regexp that doesn't flag invalid properties when there are trailing [\w] characters, e.g. --- .../eslint-plugin-circuit-ui/jest.config.js | 28 ++++++++ .../index.spec.ts | 65 ++++++++++++++++++- 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 packages/eslint-plugin-circuit-ui/jest.config.js diff --git a/packages/eslint-plugin-circuit-ui/jest.config.js b/packages/eslint-plugin-circuit-ui/jest.config.js new file mode 100644 index 0000000000..46a5ecc1c6 --- /dev/null +++ b/packages/eslint-plugin-circuit-ui/jest.config.js @@ -0,0 +1,28 @@ +/** + * Copyright 2023, SumUp Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const baseConfig = require('../../jest.config.base'); + +const packageJson = require('./package.json'); + +const packageName = packageJson.name.split('@sumup/').pop(); + +module.exports = { + ...baseConfig, + displayName: packageName, + rootDir: '../..', + roots: [`/packages/${packageName}`], + testEnvironment: 'node', +}; diff --git a/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.spec.ts b/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.spec.ts index 5a6a1058c5..dd9c6bb7e9 100644 --- a/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.spec.ts +++ b/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.spec.ts @@ -13,4 +13,67 @@ * limitations under the License. */ -// TODO +// We disable the rule in this file because we explicitly test invalid cases +/* eslint-disable @sumup/circuit-ui/no-invalid-custom-properties */ + +import { ESLintUtils } from '@typescript-eslint/utils'; + +import { noInvalidCustomProperties } from '.'; + +const ruleTester = new ESLintUtils.RuleTester({ + parser: '@typescript-eslint/parser', +}); + +ruleTester.run('no-invalid-custom-properties', noInvalidCustomProperties, { + valid: [ + { + name: 'Custom properties in JS object', + code: ` + const COLOR_MAP = { + default: "var(--cui-fg-normal)", + active: "var(--cui-fg-normal-pressed)", + } + `, + }, + { + name: 'THIS SHOULD NOT BE VALID (valid name with trailing [\\w]+)', + code: ` + const color = "var(--cui-fg-normallllllllllllll)"; + `, + }, + ], + invalid: [ + { + code: ` + const COLOR_MAP = { + default: "var(--cui-fg-norml)", + active: "var(--cui-fg-normal-active)", + } + `, + errors: [ + { + messageId: 'invalid', // first occurrence: typo + }, + { + messageId: 'invalid', // second occurrence: should be `--cui-fg-normal-pressed` + }, + ], + }, + { + code: ` + const COLOR_MAP = { + default: "var(--cui-fg-norml)", + active: "var(--cui-fg-normal-active)", + } + `, + errors: [ + { + messageId: 'invalid', // first occurrence: typo + }, + { + messageId: 'invalid', // second occurrence: should be `--cui-fg-normal-pressed` + }, + ], + }, + ], +}); From 536d0f020234f7317e05976f94e2f2e8dc62fa37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=A9tral?= Date: Wed, 15 Mar 2023 17:30:33 +0100 Subject: [PATCH 09/18] Aaaah it was the escaping of the backslash in the template literal!!! --- .../no-invalid-custom-properties/index.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.ts b/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.ts index 0735e172d9..8732f00a0f 100644 --- a/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.ts +++ b/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.ts @@ -168,11 +168,9 @@ const VALID_CUSTOM_PROPERTIES_WITHOUT_PREFIX = [ 'border-focus', ]; -/* eslint-disable no-useless-escape */ const REGEX_STRING = `(?:--cui-)(?!(?:${VALID_CUSTOM_PROPERTIES_WITHOUT_PREFIX.join( '|', -)})[^\w-])[a-zA-Z0-9-]+`; -/* eslint-enable no-useless-escape */ +)})[^\\w-])[\\w-]+`; const REGEX = new RegExp(REGEX_STRING, 'g'); const createRule = ESLintUtils.RuleCreator( From b0d3820927e94aa5f029256a156d17c048afd57c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=A9tral?= Date: Wed, 15 Mar 2023 17:37:29 +0100 Subject: [PATCH 10/18] Add tests A couple more cases coming up. The reason I want to cover different syntaxes, even though the rule only uses regex, is in case we decide to start using the AST for this rule at some point (for perf reasons or other). --- .../index.spec.ts | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.spec.ts b/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.spec.ts index dd9c6bb7e9..9cadc8342d 100644 --- a/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.spec.ts +++ b/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.spec.ts @@ -27,7 +27,7 @@ const ruleTester = new ESLintUtils.RuleTester({ ruleTester.run('no-invalid-custom-properties', noInvalidCustomProperties, { valid: [ { - name: 'Custom properties in JS object', + name: 'custom properties in a JS object', code: ` const COLOR_MAP = { default: "var(--cui-fg-normal)", @@ -35,43 +35,39 @@ ruleTester.run('no-invalid-custom-properties', noInvalidCustomProperties, { } `, }, - { - name: 'THIS SHOULD NOT BE VALID (valid name with trailing [\\w]+)', - code: ` - const color = "var(--cui-fg-normallllllllllllll)"; - `, - }, ], invalid: [ { + name: 'custom properties in a JS object', code: ` const COLOR_MAP = { default: "var(--cui-fg-norml)", - active: "var(--cui-fg-normal-active)", + active: "var(--cui-fg-pressedd)", } `, errors: [ { - messageId: 'invalid', // first occurrence: typo + messageId: 'invalid', }, { - messageId: 'invalid', // second occurrence: should be `--cui-fg-normal-pressed` + messageId: 'invalid', }, ], }, { + name: 'custom properties in a tagged template literal', code: ` - const COLOR_MAP = { - default: "var(--cui-fg-norml)", - active: "var(--cui-fg-normal-active)", - } + const styles = css\` + color: var(--cui-fg-norml); + background-color: var(--cui-bg-pressedd); + \`; `, errors: [ { - messageId: 'invalid', // first occurrence: typo + messageId: 'invalid', }, { - messageId: 'invalid', // second occurrence: should be `--cui-fg-normal-pressed` + messageId: 'invalid', }, ], }, From 2d6e3dc063cb6ec58b31948916488911ea1aa503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=A9tral?= Date: Thu, 16 Mar 2023 11:59:52 +0100 Subject: [PATCH 11/18] Fix ImageInput invalidLabel colors --- .changeset/selfish-toes-clap.md | 5 +++++ packages/circuit-ui/components/ImageInput/ImageInput.tsx | 4 ++-- .../ImageInput/__snapshots__/ImageInput.spec.tsx.snap | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 .changeset/selfish-toes-clap.md diff --git a/.changeset/selfish-toes-clap.md b/.changeset/selfish-toes-clap.md new file mode 100644 index 0000000000..3f37b69d65 --- /dev/null +++ b/.changeset/selfish-toes-clap.md @@ -0,0 +1,5 @@ +--- +'@sumup/circuit-ui': patch +--- + +Fixed the `ImageInput` component's invalid label box-shadow color. diff --git a/packages/circuit-ui/components/ImageInput/ImageInput.tsx b/packages/circuit-ui/components/ImageInput/ImageInput.tsx index deac9a41b1..c47262c28e 100644 --- a/packages/circuit-ui/components/ImageInput/ImageInput.tsx +++ b/packages/circuit-ui/components/ImageInput/ImageInput.tsx @@ -148,10 +148,10 @@ const invalidLabelStyles = ({ invalid }: LabelProps) => box-shadow: 0 0 0 2px var(--cui-border-danger); } &:hover > *:last-child { - box-shadow: 0 0 0 2px var(--cui-border-danger--hovered); + box-shadow: 0 0 0 2px var(--cui-border-danger-hovered); } &:active > *:last-child { - box-shadow: 0 0 0 2px var(--cui-border-danger--pressed); + box-shadow: 0 0 0 2px var(--cui-border-danger-pressed); } `; diff --git a/packages/circuit-ui/components/ImageInput/__snapshots__/ImageInput.spec.tsx.snap b/packages/circuit-ui/components/ImageInput/__snapshots__/ImageInput.spec.tsx.snap index 053e5a2acf..dbbcce1e2d 100644 --- a/packages/circuit-ui/components/ImageInput/__snapshots__/ImageInput.spec.tsx.snap +++ b/packages/circuit-ui/components/ImageInput/__snapshots__/ImageInput.spec.tsx.snap @@ -1748,11 +1748,11 @@ exports[`ImageInput Styles should render with invalid styles and an error messag } .circuit-3:hover>*:last-child { - box-shadow: 0 0 0 2px var(--cui-border-danger--hovered); + box-shadow: 0 0 0 2px var(--cui-border-danger-hovered); } .circuit-3:active>*:last-child { - box-shadow: 0 0 0 2px var(--cui-border-danger--pressed); + box-shadow: 0 0 0 2px var(--cui-border-danger-pressed); } .circuit-3:hover::before { From 54cd24f428b4e5aab88d453e5fca80c511974ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=A9tral?= Date: Fri, 17 Mar 2023 12:13:52 +0100 Subject: [PATCH 12/18] Add remaining test cases --- .../index.spec.ts | 54 ++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.spec.ts b/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.spec.ts index 9cadc8342d..a44e770c6c 100644 --- a/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.spec.ts +++ b/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.spec.ts @@ -22,6 +22,11 @@ import { noInvalidCustomProperties } from '.'; const ruleTester = new ESLintUtils.RuleTester({ parser: '@typescript-eslint/parser', + parserOptions: { + ecmaFeatures: { + jsx: true, + }, + }, }); ruleTester.run('no-invalid-custom-properties', noInvalidCustomProperties, { @@ -35,6 +40,29 @@ ruleTester.run('no-invalid-custom-properties', noInvalidCustomProperties, { } `, }, + { + name: 'custom properties in a tagged template literal', + code: ` + const styles = css\` + color: var(--cui-fg-normal); + background-color: var(--cui-fg-normal-pressed); + \`; + `, + }, + { + name: 'custom properties in inline styles', + code: ` + function Component() { + return ( +

+ Success +

+ ); + } + `, + }, ], invalid: [ { @@ -42,7 +70,7 @@ ruleTester.run('no-invalid-custom-properties', noInvalidCustomProperties, { code: ` const COLOR_MAP = { default: "var(--cui-fg-norml)", - active: "var(--cui-fg-pressedd)", + active: "var(--cui-fg-normal-pressedd)", } `, errors: [ @@ -59,7 +87,7 @@ ruleTester.run('no-invalid-custom-properties', noInvalidCustomProperties, { code: ` const styles = css\` color: var(--cui-fg-norml); - background-color: var(--cui-bg-pressedd); + background-color: var(--cui-fg-normal-pressedd); \`; `, errors: [ @@ -71,5 +99,27 @@ ruleTester.run('no-invalid-custom-properties', noInvalidCustomProperties, { }, ], }, + { + name: 'custom properties in inline styles', + code: ` + function Component() { + return ( +

+ Success +

+ ); + } + `, + errors: [ + { + messageId: 'invalid', + }, + { + messageId: 'invalid', + }, + ], + }, ], }); From 412b5c3e3cd4e57bc64da782bd5300e469f38079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=A9tral?= Date: Fri, 17 Mar 2023 12:18:28 +0100 Subject: [PATCH 13/18] Add changesets --- .changeset/rare-colts-agree.md | 5 +++++ packages/eslint-plugin-circuit-ui/package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/rare-colts-agree.md diff --git a/.changeset/rare-colts-agree.md b/.changeset/rare-colts-agree.md new file mode 100644 index 0000000000..6a6f8bb29d --- /dev/null +++ b/.changeset/rare-colts-agree.md @@ -0,0 +1,5 @@ +--- +'@sumup/eslint-plugin-circuit-ui': patch +--- + +Released ESLint rules to lint Circuit UI in `@sumup/eslint-plugin-circuit-ui`. diff --git a/packages/eslint-plugin-circuit-ui/package.json b/packages/eslint-plugin-circuit-ui/package.json index 2fa1058210..abc0d8d0e0 100644 --- a/packages/eslint-plugin-circuit-ui/package.json +++ b/packages/eslint-plugin-circuit-ui/package.json @@ -1,6 +1,6 @@ { "name": "@sumup/eslint-plugin-circuit-ui", - "version": "1.0.0", + "version": "0.0.1", "description": "ESLint rules to lint Circuit UI.", "main": "dist/index.js", "files": [ From 6b31b24fa42dfcc14eedc26a48fdf2ae8ff6db55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=A9tral?= Date: Fri, 17 Mar 2023 12:21:57 +0100 Subject: [PATCH 14/18] Fix version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 94afb44a52..20f21b7682 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "@storybook/source-loader": "^7.0.0-beta.60", "@storybook/testing-library": "^0.0.14-next.1", "@storybook/theming": "^7.0.0-beta.60", - "@sumup/eslint-plugin-circuit-ui": "^1.0.0", + "@sumup/eslint-plugin-circuit-ui": "^0.0.1", "@sumup/foundry": "^5.1.0", "@types/jest": "^29.5.0", "@types/node": "^18.15.3", From 236127cb5b8b5d9d40a3eda8e6b3dc145a736218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=A9tral?= Date: Mon, 20 Mar 2023 11:16:08 +0100 Subject: [PATCH 15/18] Add docs --- docs/features/1-theme.mdx | 2 ++ docs/introduction/2-getting-started.mdx | 2 ++ packages/eslint-plugin-circuit-ui/README.md | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/features/1-theme.mdx b/docs/features/1-theme.mdx index d5ca6c52de..c43d22cbda 100644 --- a/docs/features/1-theme.mdx +++ b/docs/features/1-theme.mdx @@ -31,6 +31,8 @@ The Circuit UI theme is moving from color scales (e.g. `g900`) to semantic color Additionally, color tokens are moving from the JS theme (exported from `@sumup/design-tokens`) to [CSS custom properties](https://www.w3.org/TR/css-variables-1/), declared in the Circuit UI `BaseStyles` from version 6.1.0. This has performance benefits over CSS-in-JS theming. Eventually, all design tokens will be declared as CSS custom properties. +To make it easier to work with custom properties, we recommend using the [`@sumup/eslint-plugin-circuit-ui`](Packages/eslint-plugin-circuit-ui/Docs) ESLint plugin, and turning on the `no-invalid-custom-properties` rule. + #### Background colors Date: Mon, 20 Mar 2023 11:35:20 +0100 Subject: [PATCH 16/18] Add test case --- .../no-invalid-custom-properties/index.spec.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.spec.ts b/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.spec.ts index a44e770c6c..e8cfb8c0a8 100644 --- a/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.spec.ts +++ b/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/index.spec.ts @@ -121,5 +121,18 @@ ruleTester.run('no-invalid-custom-properties', noInvalidCustomProperties, { }, ], }, + { + name: 'string interpolation in custom properties', + code: ` + const styles = css\` + color: var(--cui-fg-\${variant}); + \`; + `, + errors: [ + { + messageId: 'invalid', + }, + ], + }, ], }); From 99bad9ebc11fc023388465b4ab081e2c3a946280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=A9tral?= Date: Mon, 20 Mar 2023 12:02:27 +0100 Subject: [PATCH 17/18] Add eslintignore to package We could also ignore js config files globally from the root .eslintignore, but since there's already a file in every package, I'm following the same approach for . --- packages/eslint-plugin-circuit-ui/.eslintignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 packages/eslint-plugin-circuit-ui/.eslintignore diff --git a/packages/eslint-plugin-circuit-ui/.eslintignore b/packages/eslint-plugin-circuit-ui/.eslintignore new file mode 100644 index 0000000000..81ddf0f27e --- /dev/null +++ b/packages/eslint-plugin-circuit-ui/.eslintignore @@ -0,0 +1,3 @@ +node_modules/ +dist/ +jest.config.js From ba51a1821113d7a0964ab318096f53407a6494ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=A9tral?= Date: Mon, 20 Mar 2023 12:34:56 +0100 Subject: [PATCH 18/18] Ah no coverage was somewhere else --- jest.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/jest.config.js b/jest.config.js index 0818e5b070..1c09d5b14b 100644 --- a/jest.config.js +++ b/jest.config.js @@ -27,5 +27,6 @@ module.exports = { '!/packages/**/index.{ts,tsx,js,jsx}', '!/packages/**/*.stories.{ts,tsx,js,jsx}', '!/packages/**/*.docs.mdx', + '!/packages/**/*.config.js', ], };