|
| 1 | +/** |
| 2 | + * Copyright (C) 2023 Green Code Initiative |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | +"use strict"; |
| 18 | + |
| 19 | +//------------------------------------------------------------------------------ |
| 20 | +// Requirements |
| 21 | +//------------------------------------------------------------------------------ |
| 22 | + |
| 23 | +const rule = require("../../../lib/rules/avoid-css-animations"); |
| 24 | +const RuleTester = require("eslint").RuleTester; |
| 25 | + |
| 26 | +//------------------------------------------------------------------------------ |
| 27 | +// Tests |
| 28 | +//------------------------------------------------------------------------------ |
| 29 | + |
| 30 | +const ruleTester = new RuleTester({ |
| 31 | + parserOptions: { |
| 32 | + ecmaVersion: 2021, |
| 33 | + sourceType: "module", |
| 34 | + ecmaFeatures: { |
| 35 | + jsx: true, |
| 36 | + }, |
| 37 | + }, |
| 38 | +}); |
| 39 | + |
| 40 | +ruleTester.run("avoid-css-animations", rule, { |
| 41 | + valid: [ |
| 42 | + ` |
| 43 | + import React from 'react'; |
| 44 | + import './styles.css'; // External CSS file |
| 45 | +
|
| 46 | + const MyComponent = () => { |
| 47 | + return <div className="my-class">This content is styled using an external CSS file.</div>; |
| 48 | + }; |
| 49 | +
|
| 50 | + export default MyComponent; |
| 51 | + `, |
| 52 | + `<div style={{ width: '100px', height: '100px' }}>Hello world</div>`, |
| 53 | + `<div style="border: 2px solid red">My red element</div>`, |
| 54 | + ], |
| 55 | + |
| 56 | + invalid: [ |
| 57 | + { |
| 58 | + code: "<div style={{ transition: 'width 2s' }} />", |
| 59 | + errors: [ |
| 60 | + { |
| 61 | + messageId: "AvoidCSSAnimations", |
| 62 | + data: { |
| 63 | + attribute: "transition", |
| 64 | + }, |
| 65 | + type: "Property", |
| 66 | + }, |
| 67 | + ], |
| 68 | + }, |
| 69 | + { |
| 70 | + code: "<div style={{ animationName: 'example', animationDuration: '4s' }} />", |
| 71 | + errors: [ |
| 72 | + { |
| 73 | + messageId: "AvoidCSSAnimations", |
| 74 | + data: { |
| 75 | + attribute: "animationName", |
| 76 | + }, |
| 77 | + type: "Property", |
| 78 | + }, |
| 79 | + ], |
| 80 | + }, |
| 81 | + ], |
| 82 | +}); |
0 commit comments