Skip to content

Commit

Permalink
Replace cannot by shouldn’t
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayc0 committed Mar 7, 2024
1 parent 711bb39 commit 82aba1f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ This ESLint plugin comes with multiple rules to help you apply some pattern on v

## Rules

- [Rules](#rules)
- [preferred-export-default-naming](#preferred-export-default-naming)
- [Configuration](#configuration)
- [Example](#example)
- [prevent-imports](#prevent-imports)
- [Configuration](#configuration-1)
- [Example](#example-1)
1. [Rules](#rules)
1. [preferred-export-default-naming](#preferred-export-default-naming)
1. [Configuration](#configuration)
2. [Example](#example)
2. [prevent-imports](#prevent-imports)
1. [Configuration](#configuration-1)
2. [Example](#example-1)

### preferred-export-default-naming

Expand Down Expand Up @@ -100,7 +100,7 @@ This rule enforces a default name for export default & namespace. By default, de
*/

//
import { findDOMNode } from "react-dom"; // findDOMNode cannot be imported
import { findDOMNode } from "react-dom"; // findDOMNode shouldn’t be imported

import * as ReactDOM from "react-dom";
ReactDOM.findDOMNode(); // ❌ It recognizes that findDOMNode is from react-dom
Expand All @@ -123,14 +123,14 @@ You can specify a reason why multiple imports are forbidden:
*/

//
import type { FC } from "react"; // Error: `You cannot import "FC" from "react": Prefer React.VoidFunctionComponent`
import type { FC } from "react"; // Error: `You shouldn’t import "FC" from "react": Prefer React.VoidFunctionComponent`
const MyComponent: FC = () => {};

import React from "react";
const MyComponent: React.FunctionComponent = () => {}; // Error: `You cannot use "FunctionComponent" from "react": Prefer React.VoidFunctionComponent`
const MyComponent: React.FunctionComponent = () => {}; // Error: `You shouldn’t use "FunctionComponent" from "react": Prefer React.VoidFunctionComponent`

import * as React from "react";
const MyComponent: React.VFC = () => {}; // Error: `You cannot use "VFC" from "react": Prefer React.VoidFunctionComponent`
const MyComponent: React.VFC = () => {}; // Error: `You shouldn’t use "VFC" from "react": Prefer React.VoidFunctionComponent`

//
import * as React from "react";
Expand Down
4 changes: 2 additions & 2 deletions src/prevent-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const rule: Rule.RuleModule = {
continue;
}

let message = `You cannot import "${matchedName}" from "${foundOption.module}"`;
let message = `You shouldn’t import "${matchedName}" from "${foundOption.module}"`;
if (foundOption.reason) {
message += `: ${foundOption.reason}`;
}
Expand Down Expand Up @@ -138,7 +138,7 @@ const rule: Rule.RuleModule = {
) {
continue;
}
let message = `You cannot use "${property}" from "${elementToCheck.module}"`;
let message = `You shouldn’t use "${property}" from "${elementToCheck.module}"`;
if (elementToCheck.reason) {
message += `: ${elementToCheck.reason}`;
}
Expand Down
14 changes: 7 additions & 7 deletions tests/prevent-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ const suites: Array<{
},
],
errors: [
'You cannot import "a" from "b"',
'You cannot use "d" from "c": Prefer f',
'You cannot use "e" from "c": Prefer f',
'You shouldn’t import "a" from "b"',
'You shouldn’t use "d" from "c": Prefer f',
'You shouldn’t use "e" from "c": Prefer f',
],
},

Expand All @@ -57,10 +57,10 @@ const suites: Array<{
},
],
errors: [
'You cannot import "b" from "a": B',
'You cannot import "c" from "a": C',
'You cannot use "b" from "a": B',
'You cannot use "c" from "a": C',
'You shouldn’t import "b" from "a": B',
'You shouldn’t import "c" from "a": C',
'You shouldn’t use "b" from "a": B',
'You shouldn’t use "c" from "a": C',
],
},
];
Expand Down

0 comments on commit 82aba1f

Please sign in to comment.