New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[prefer-readonly-type] - Add an option to opt out of function parameters check #91
Comments
Are you referring to the rule prefer-readonly-parameters ? |
@avalanche1, I assume you are creating a React Functional Component in the given example. Wouldn't it be best to pull out the prop's type into it's own declared type like this: type Props = {
readonly text: string;
}
export function UserCanSeeStoryboardDashboard({ text }: Props): JSX.Element {
// ...
} Also, the return type of such an function should be of type type Props = {
readonly text: string;
}
type Element = React.FunctionalComponentElement<Props>;
export function UserCanSeeStoryboardDashboard({ text }: Props): Element {
// ...
} If you use an arrow function expression instead of a function declaration, you can just declare the function as a whole to be a type Props = {
readonly text: string;
}
type Component = React.FunctionalComponent<Props>;
export const UserCanSeeStoryboardDashboard: Component = ({ text }) => {
// ...
}; |
It depends. If there are multiple params - then yes. If there is one-two params - why the bloat?
Our code style guide prohibits usage of function expressions. We like top-down approach to code which Makes heavy use of function hoisting (which is why we ❤️ JS). |
In my opinion this wouldn't be bloat; instead it would be a separation of type and executable code.
|
I think I'm going to close this issue as parameters should be readonly. |
The
readonly
word in fn parameters when declaring a function takes up really much editor space. With mymax-len
settings my editor breaks up a simple functional component declaration into many lines.I have another es-lint rule that checks that fn arguments are not mutated.
I like:
I don't like:
The text was updated successfully, but these errors were encountered: