Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit d16891c

Browse files
authored
chore(eslint): add lint rule to disable access modifiers (#1458)
* chore(eslint): add lint rule to disable access modifiers * fix files * fixes for master, final cleanup * apply only for .tsx files * fix review comment
1 parent f91573e commit d16891c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+467
-345
lines changed

build/gulp/tasks/test-projects.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const packStardustPackages = async (logger: Function): Promise<PackedPackages> =
4646
const stardustPackages = lernaAliases({ sourceDirectory: false })
4747

4848
// We don't want to pack a package with our dev tools
49+
delete stardustPackages['@stardust-ui/eslint-plugin']
4950
delete stardustPackages['@stardust-ui/internal-tooling']
5051

5152
await Promise.all(

build/gulp/tasks/test-projects/cra/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import * as React from 'react'
1717

1818
class App extends React.Component {
19-
public render() {
19+
render() {
2020
return (
2121
<Provider theme={themes.teams}>
2222
<div>

docs/src/components/ComponentDoc/ComponentControls/ComponentControlsCopyLink.tsx

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ import ComponentButton from './ComponentButton'
33
import * as _ from 'lodash'
44

55
export default class ComponentControlsCopyLink extends React.Component<any, any> {
6-
private mounted: boolean
7-
private readonly btnLabel = 'Permalink'
6+
mounted: boolean
7+
readonly btnLabel = 'Permalink'
88

9-
public state: any = {}
9+
state: any = {}
1010

11-
public shouldComponentUpdate(nextProps, nextState) {
11+
shouldComponentUpdate(nextProps, nextState) {
1212
return this.state.active !== nextState.active
1313
}
1414

15-
public componentDidMount() {
15+
componentDidMount() {
1616
this.mounted = true
1717
}
1818

19-
public componentWillUnmount() {
19+
componentWillUnmount() {
2020
this.mounted = false
2121
}
2222

23-
public render() {
23+
render() {
2424
const { active } = this.state
2525

2626
return (
@@ -32,13 +32,13 @@ export default class ComponentControlsCopyLink extends React.Component<any, any>
3232
)
3333
}
3434

35-
private handleClick = e => {
35+
handleClick = e => {
3636
e.preventDefault()
3737
_.invoke(this.props, 'onClick', e, this.props)
3838

3939
this.setState({ active: true })
4040
setTimeout(this.resetActive, 3000)
4141
}
4242

43-
private resetActive = () => this.mounted && this.setState({ active: false })
43+
resetActive = () => this.mounted && this.setState({ active: false })
4444
}

docs/src/components/ComponentDoc/ComponentExamples.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ interface ComponentExamplesProps {
1313
}
1414

1515
export default class ComponentExamples extends React.Component<ComponentExamplesProps, any> {
16-
public static propTypes = {
16+
static propTypes = {
1717
displayName: PropTypes.string.isRequired,
1818
}
1919

20-
public render() {
20+
render() {
2121
return this.renderExamples() || this.renderMissingExamples()
2222
}
2323

@@ -29,7 +29,7 @@ export default class ComponentExamples extends React.Component<ComponentExamples
2929
* 2. for every ./docs/src/components/{...}/{...}MyComponent{...}Example{...}.tsx there needs to be a shorthand version of it:
3030
* ./docs/src/components/{...}/{...}MyComponent{...}Example{...}.shorthand.tsx
3131
*/
32-
private renderExamples = (): JSX.Element | null => {
32+
renderExamples = (): JSX.Element | null => {
3333
const { displayName } = this.props
3434

3535
// rule #1
@@ -56,7 +56,7 @@ export default class ComponentExamples extends React.Component<ComponentExamples
5656
)
5757
}
5858

59-
private renderMissingExamples = () => {
59+
renderMissingExamples = () => {
6060
const { displayName } = this.props
6161

6262
return this.renderElementWrappedInGrid(
@@ -66,7 +66,7 @@ export default class ComponentExamples extends React.Component<ComponentExamples
6666
)
6767
}
6868

69-
private renderMissingShorthandExamples = (missingPaths: string[]) => {
69+
renderMissingShorthandExamples = (missingPaths: string[]) => {
7070
return this.renderElementWrappedInGrid(
7171
<ContributionPrompt>
7272
<div>Looks like we're missing examples at following paths:</div>
@@ -75,9 +75,9 @@ export default class ComponentExamples extends React.Component<ComponentExamples
7575
)
7676
}
7777

78-
private renderElementWrappedInGrid = (Element: JSX.Element) => <Segment content={Element} />
78+
renderElementWrappedInGrid = (Element: JSX.Element) => <Segment content={Element} />
7979

80-
private getMissingExamplePaths(displayName: string, allPaths: string[]): string[] {
80+
getMissingExamplePaths(displayName: string, allPaths: string[]): string[] {
8181
const examplesPattern = `\./${displayName}/[\\w/]+Example`
8282
const [normalExtension, shorthandExtension] = [
8383
componentAPIs.children.fileSuffix,

docs/src/components/CopyToClipboard.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class CopyToClipboard extends React.Component<CopyToClipboardProps, CopyToClipbo
1616
active: false,
1717
}
1818

19-
private timeoutId
19+
timeoutId
2020

2121
static defaultProps = {
2222
timeout: 3000,

docs/src/components/Sidebar/Sidebar.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Sidebar extends React.Component<any, any> {
5252
this._searchInput = (findDOMNode(this) as any).querySelector('.ui.input input')
5353
}
5454

55-
private handleDocumentKeyDown = e => {
55+
handleDocumentKeyDown = e => {
5656
const code = keyboardKey.getCode(e)
5757
const isAZ = code >= 65 && code <= 90
5858
const hasModifier = e.altKey || e.ctrlKey || e.metaKey
@@ -61,7 +61,7 @@ class Sidebar extends React.Component<any, any> {
6161
if (!hasModifier && isAZ && bodyHasFocus) this._searchInput.focus()
6262
}
6363

64-
private handleItemClick = () => {
64+
handleItemClick = () => {
6565
const { query } = this.state
6666

6767
if (query) this.setState({ query: '' })

docs/src/prototypes/IconViewer/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const renderStardustIconName = (icon, isOutline = false) => {
3333
}
3434

3535
class IconViewerExample extends React.Component<any, {}> {
36-
private readonly iconFilters = {
36+
readonly iconFilters = {
3737
All: () => true,
3838
Exported: (icon: TeamsProcessedSvgIconSpec) => icon.exportedAs,
3939
'Not Exported': (icon: TeamsProcessedSvgIconSpec) => !icon.exportedAs,

docs/src/prototypes/chatPane/chatPaneContent.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import chatProtoStyle from './chatProtoStyle'
99
export type ChatPaneContainerProps = Props<{ chat: ChatData }>
1010

1111
class ChatPaneContainer extends React.PureComponent<ChatPaneContainerProps> {
12-
public render() {
12+
render() {
1313
const { chat } = this.props
1414
const items = this.generateChatItems(chat)
1515

@@ -35,7 +35,7 @@ class ChatPaneContainer extends React.PureComponent<ChatPaneContainerProps> {
3535
)
3636
}
3737

38-
private generateChatItems(chat: ChatData): JSX.Element[] {
38+
generateChatItems(chat: ChatData): JSX.Element[] {
3939
return generateChatProps(chat).map(
4040
({ mine, gutter, message: { itemType, ...props } }, index) => {
4141
const ElementType = this.getElementType(itemType)
@@ -73,7 +73,7 @@ class ChatPaneContainer extends React.PureComponent<ChatPaneContainerProps> {
7373
)
7474
}
7575

76-
private getElementType = (itemType: ChatItemTypes): React.ElementType => {
76+
getElementType = (itemType: ChatItemTypes): React.ElementType => {
7777
switch (itemType) {
7878
case ChatItemTypes.message:
7979
return Chat.Message
@@ -82,13 +82,13 @@ class ChatPaneContainer extends React.PureComponent<ChatPaneContainerProps> {
8282
}
8383
}
8484

85-
private handleScrollRef(scrollRef: Scrollbars) {
85+
handleScrollRef(scrollRef: Scrollbars) {
8686
if (scrollRef) {
8787
scrollRef.scrollToBottom()
8888
}
8989
}
9090

91-
private getMessagePreviewForScreenReader(props) {
91+
getMessagePreviewForScreenReader(props) {
9292
/* Show the first 44 characters from the message, reasons:
9393
- as NVDA splits it into 2 lines if more is shown
9494
- for announcements feature, messaging team went with 44 characters but that was not based on loc issues but some UI real estate issue. */

docs/src/prototypes/chatPane/chatPaneHeader.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface ChatPaneHeaderProps {
99
}
1010

1111
class ChatPaneHeader extends React.PureComponent<ChatPaneHeaderProps> {
12-
public render() {
12+
render() {
1313
return (
1414
<Flex column>
1515
<Flex.Item>{this.renderBanner()}</Flex.Item>
@@ -19,7 +19,7 @@ class ChatPaneHeader extends React.PureComponent<ChatPaneHeaderProps> {
1919
)
2020
}
2121

22-
private renderBanner(): React.ReactElement {
22+
renderBanner(): React.ReactElement {
2323
return (
2424
<Segment
2525
content={
@@ -41,7 +41,7 @@ class ChatPaneHeader extends React.PureComponent<ChatPaneHeaderProps> {
4141
)
4242
}
4343

44-
private renderMainArea(): React.ReactElement {
44+
renderMainArea(): React.ReactElement {
4545
const { chat } = this.props
4646

4747
return (
@@ -74,7 +74,7 @@ class ChatPaneHeader extends React.PureComponent<ChatPaneHeaderProps> {
7474
)
7575
}
7676

77-
private renderHeaderButtons(): React.ReactElement {
77+
renderHeaderButtons(): React.ReactElement {
7878
return (
7979
<div style={{ display: 'inline-flex' }}>
8080
<Button.Group

docs/src/prototypes/mentions/PortalAtCursorPosition.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ export interface PortalAtCursorPositionProps {
88
}
99

1010
export class PortalAtCursorPosition extends React.Component<PortalAtCursorPositionProps> {
11-
private mountNodeInstance: HTMLElement = null
11+
mountNodeInstance: HTMLElement = null
1212

1313
static defaultProps = {
1414
mountNodeId: 'portal-at-cursor-position',
1515
}
1616

17-
public componentWillUnmount() {
17+
componentWillUnmount() {
1818
this.removeMountNode()
1919
}
2020

21-
public render() {
21+
render() {
2222
const { children, open } = this.props
2323

2424
this.setupMountNode()
@@ -27,7 +27,7 @@ export class PortalAtCursorPosition extends React.Component<PortalAtCursorPositi
2727
: null
2828
}
2929

30-
private setupMountNode = () => {
30+
setupMountNode = () => {
3131
const { mountNodeId, open } = this.props
3232

3333
if (open) {
@@ -37,7 +37,7 @@ export class PortalAtCursorPosition extends React.Component<PortalAtCursorPositi
3737
}
3838
}
3939

40-
private removeMountNode = () => {
40+
removeMountNode = () => {
4141
if (this.mountNodeInstance) {
4242
removeElement(this.mountNodeInstance)
4343
this.mountNodeInstance = null

packages/eslint-plugin/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
rules: {
3+
'no-visibility-modifiers': require('./rules/no-visibility-modifiers'),
4+
},
5+
}

packages/eslint-plugin/package.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "@stardust-ui/eslint-plugin",
3+
"version": "0.31.0",
4+
"dependencies": {
5+
"@typescript-eslint/eslint-plugin": "^1.9.0",
6+
"@typescript-eslint/experimental-utils": "^1.9.0"
7+
},
8+
"files": [
9+
"rules"
10+
],
11+
"publishConfig": {
12+
"access": "public"
13+
}
14+
}

0 commit comments

Comments
 (0)