|
| 1 | +/* |
| 2 | + * creedengo JavaScript plugin - Provides rules to reduce the environmental footprint of your JavaScript programs |
| 3 | + * Copyright © 2023 Green Code Initiative (https://green-code-initiative.org) |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | + |
| 19 | +"use strict"; |
| 20 | + |
| 21 | +//------------------------------------------------------------------------------ |
| 22 | +// Requirements |
| 23 | +//------------------------------------------------------------------------------ |
| 24 | + |
| 25 | +const rule = require("../../../lib/rules/no-imported-number-format-library"); |
| 26 | +const RuleTester = require("eslint").RuleTester; |
| 27 | + |
| 28 | +//------------------------------------------------------------------------------ |
| 29 | +// Tests |
| 30 | +//------------------------------------------------------------------------------ |
| 31 | + |
| 32 | +const ruleTester = new RuleTester({ |
| 33 | + parserOptions: { |
| 34 | + ecmaVersion: 6, |
| 35 | + sourceType: "module", |
| 36 | + }, |
| 37 | +}); |
| 38 | +const expectedError = { |
| 39 | + messageId: "ShouldNotUseImportedNumberFormatLibrary", |
| 40 | + type: "Identifier", |
| 41 | +}; |
| 42 | + |
| 43 | +ruleTester.run("no-imported-number-format-library", rule, { |
| 44 | + valid: [ |
| 45 | + "new Intl.NumberFormat().format(1000);", |
| 46 | + "numbro(1000).add(5);", |
| 47 | + ` |
| 48 | + const number = numbro(1000); |
| 49 | + const number2 = numbro(2000); |
| 50 | + number2.add(1000); |
| 51 | + `, |
| 52 | + ], |
| 53 | + invalid: [ |
| 54 | + { |
| 55 | + code: "numbro(1000).format({thousandSeparated: true});", |
| 56 | + errors: [expectedError], |
| 57 | + }, |
| 58 | + { |
| 59 | + code: ` |
| 60 | + const number = numbro(1000); |
| 61 | + number.format({thousandSeparated: true}); |
| 62 | + `, |
| 63 | + errors: [expectedError], |
| 64 | + }, |
| 65 | + { |
| 66 | + code: ` |
| 67 | + const number = numbro(1000); |
| 68 | + const number2 = numbro(2000); |
| 69 | + number.format({thousandSeparated: true}); |
| 70 | + `, |
| 71 | + errors: [expectedError], |
| 72 | + }, |
| 73 | + ], |
| 74 | +}); |
0 commit comments