@sumup-oss/eslint-plugin-circuit-ui
Version:
ESLint rules to lint Circuit UI.
135 lines (134 loc) • 3.71 kB
JavaScript
/**
* 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.
*/
// We disable the rule in this file because we explicitly test invalid cases
/* eslint-disable circuit-ui/no-invalid-custom-properties */
import { RuleTester } from '@typescript-eslint/rule-tester';
import { noInvalidCustomProperties } from './index.js';
const ruleTester = new RuleTester({
languageOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
});
ruleTester.run('no-invalid-custom-properties', noInvalidCustomProperties, {
valid: [
{
name: 'custom properties in a JS object',
code: `
const COLOR_MAP = {
default: "var(--cui-fg-normal)",
active: "var(--cui-fg-normal-pressed)",
}
`,
},
{
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 (
<p
style="color:var(--cui-fg-normal);background-color:var(--cui-fg-normal-pressed);"
>
Success
</p>
);
}
`,
},
],
invalid: [
{
name: 'custom properties in a JS object',
code: `
const COLOR_MAP = {
default: "var(--cui-fg-norml)",
active: "var(--cui-fg-normal-pressedd)",
}
`,
errors: [
{
messageId: 'invalid',
},
{
messageId: 'invalid',
},
],
},
{
name: 'custom properties in a tagged template literal',
code: `
const styles = css\`
color: var(--cui-fg-norml);
background-color: var(--cui-fg-normal-pressedd);
\`;
`,
errors: [
{
messageId: 'invalid',
},
{
messageId: 'invalid',
},
],
},
{
name: 'custom properties in inline styles',
code: `
function Component() {
return (
<p
style="color:var(--cui-fg-norml);background-color:var(--cui-fg-normal-pressedd);"
>
Success
</p>
);
}
`,
errors: [
{
messageId: 'invalid',
},
{
messageId: 'invalid',
},
],
},
{
name: 'string interpolation in custom properties',
code: `
const styles = css\`
color: var(--cui-fg-\${variant});
\`;
`,
errors: [
{
messageId: 'invalid',
},
],
},
],
});