-
Notifications
You must be signed in to change notification settings - Fork 76
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
Can't use Pascal case when declaring a stateless functional component (SFC) #120
Comments
For now, I'm doing this, but it's just a hack, as it allows people to write all vars as Pascal case.
|
👍 |
Also running into this. Bump. |
Any update on this? |
Need some workaround too, to be used in pair with React project. Until then turned this rule off. |
Would there be any way to allow PascalCase on a Stateless Component if it preceded by the // will cause an error
const DummyComponent = (props) => {
return <div>Hello World!</div>;
}; // is allowed, as component is now typed
const DummyComponent: React.SFC<DummyComponentProps> = (props) => {
return <div>Hello World!</div>;
}; |
You can do this:
|
my 2 cents @nickytonline
and now it is fine |
I wouldn't limit it to functional components, since it'll complain about any import React from 'react';
import styled from 'styled-components';
// Returns a `StyledComponent`.
const StyledBox = styled.div``;
// Returns a `LazyExoticComponent`.
const LazyBox = React.lazy(() => import('./Box'));
// Returns a `MemoExoticComponent`.
const MemoBox = memo(Box); |
also happens with React Contexts example from the documentation: const ThemeContext = React.createContext('light');
...
<ThemeContext.Provider value="dark">
<Toolbar />
</ThemeContext.Provider>
... |
I dont know the problem but I found a solution ... if I use: // in ./app.ts
import MyComponent from './components/myComponent'; I get this: Error : `Misnamed import. Import should be named 'myComponent' but found 'MyComponent'
(import-name)tslint(1)` even with that: {
"extends": ["tslint:recommended", "tslint-config-airbnb", "tslint-config-prettier", "tslint-react"],
// This rule is here for now because of https://github.com/palantir/tslint-react/issues/120
"variable-name": [
true,
"ban-keywords",
"check-format",
"allow-pascal-case",
"allow-leading-underscore",
"allow-trailing-underscore"
]
} I dont know if I am doing it right ? this is my solution : // in ./components/myComponent.ts
export const myComponent = props => {
/* ... using props somewhere in my function ... */
};
// in ./app.ts
import { myComponent as MyComponent } from './components/myComponent';
// or
// in ./components/myComponent.ts
export default props => {
/* ... using props somewhere in my function ... */
};
// in ./app.ts
import { default as MyComponent } from './components/myComponent'; |
Any progress on this? It's kind of a PIA to deal with this in react components. |
I think the AirBnb style guide explicitly states why this rule is in effect. You can turn if off if you like: |
I don't think type-aware variable naming is going to be added to tslint given the deprecation timeline (#210). Until now we've been happy with allowing pascal case for all variable names, so I consider that a sufficient workaround. |
I'm currently having issues declaring SFCs when using the following tslint configuration:
and here is a sample component
which results in the error
I know that it is the
tslint-config-airbnb
causing the issue, but I would have thought that tslint-react would have a rule for Pascal cased SFCs.I think that this rule is missing. I'd be happy to throw up a PR if that's the case. I just need to read up a bit on creating rules.
The text was updated successfully, but these errors were encountered: