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

chore(eslint): add lint rule to disable access modifiers #1458

Merged
merged 6 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/gulp/tasks/test-projects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const packStardustPackages = async (logger: Function): Promise<PackedPackages> =
const stardustPackages = lernaAliases({ sourceDirectory: false })

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

await Promise.all(
Expand Down
2 changes: 1 addition & 1 deletion build/gulp/tasks/test-projects/cra/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import * as React from 'react'

class App extends React.Component {
public render() {
render() {
return (
<Provider theme={themes.teams}>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ import ComponentButton from './ComponentButton'
import * as _ from 'lodash'

export default class ComponentControlsCopyLink extends React.Component<any, any> {
private mounted: boolean
private readonly btnLabel = 'Permalink'
mounted: boolean
readonly btnLabel = 'Permalink'

public state: any = {}
state: any = {}

public shouldComponentUpdate(nextProps, nextState) {
shouldComponentUpdate(nextProps, nextState) {
return this.state.active !== nextState.active
}

public componentDidMount() {
componentDidMount() {
this.mounted = true
}

public componentWillUnmount() {
componentWillUnmount() {
this.mounted = false
}

public render() {
render() {
const { active } = this.state

return (
Expand All @@ -32,13 +32,13 @@ export default class ComponentControlsCopyLink extends React.Component<any, any>
)
}

private handleClick = e => {
handleClick = e => {
e.preventDefault()
_.invoke(this.props, 'onClick', e, this.props)

this.setState({ active: true })
setTimeout(this.resetActive, 3000)
}

private resetActive = () => this.mounted && this.setState({ active: false })
resetActive = () => this.mounted && this.setState({ active: false })
}
14 changes: 7 additions & 7 deletions docs/src/components/ComponentDoc/ComponentExamples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ interface ComponentExamplesProps {
}

export default class ComponentExamples extends React.Component<ComponentExamplesProps, any> {
public static propTypes = {
static propTypes = {
displayName: PropTypes.string.isRequired,
}

public render() {
render() {
return this.renderExamples() || this.renderMissingExamples()
}

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

// rule #1
Expand All @@ -56,7 +56,7 @@ export default class ComponentExamples extends React.Component<ComponentExamples
)
}

private renderMissingExamples = () => {
renderMissingExamples = () => {
const { displayName } = this.props

return this.renderElementWrappedInGrid(
Expand All @@ -66,7 +66,7 @@ export default class ComponentExamples extends React.Component<ComponentExamples
)
}

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

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

private getMissingExamplePaths(displayName: string, allPaths: string[]): string[] {
getMissingExamplePaths(displayName: string, allPaths: string[]): string[] {
const examplesPattern = `\./${displayName}/[\\w/]+Example`
const [normalExtension, shorthandExtension] = [
componentAPIs.children.fileSuffix,
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/CopyToClipboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CopyToClipboard extends React.Component<CopyToClipboardProps, CopyToClipbo
active: false,
}

private timeoutId
timeoutId

static defaultProps = {
timeout: 3000,
Expand Down
4 changes: 2 additions & 2 deletions docs/src/components/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Sidebar extends React.Component<any, any> {
this._searchInput = (findDOMNode(this) as any).querySelector('.ui.input input')
}

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

private handleItemClick = () => {
handleItemClick = () => {
const { query } = this.state

if (query) this.setState({ query: '' })
Expand Down
2 changes: 1 addition & 1 deletion docs/src/prototypes/IconViewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const renderStardustIconName = (icon, isOutline = false) => {
}

class IconViewerExample extends React.Component<any, {}> {
private readonly iconFilters = {
readonly iconFilters = {
All: () => true,
Exported: (icon: TeamsProcessedSvgIconSpec) => icon.exportedAs,
'Not Exported': (icon: TeamsProcessedSvgIconSpec) => !icon.exportedAs,
Expand Down
10 changes: 5 additions & 5 deletions docs/src/prototypes/chatPane/chatPaneContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import chatProtoStyle from './chatProtoStyle'
export type ChatPaneContainerProps = Props<{ chat: ChatData }>

class ChatPaneContainer extends React.PureComponent<ChatPaneContainerProps> {
public render() {
render() {
const { chat } = this.props
const items = this.generateChatItems(chat)

Expand All @@ -35,7 +35,7 @@ class ChatPaneContainer extends React.PureComponent<ChatPaneContainerProps> {
)
}

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

private getElementType = (itemType: ChatItemTypes): React.ElementType => {
getElementType = (itemType: ChatItemTypes): React.ElementType => {
switch (itemType) {
case ChatItemTypes.message:
return Chat.Message
Expand All @@ -82,13 +82,13 @@ class ChatPaneContainer extends React.PureComponent<ChatPaneContainerProps> {
}
}

private handleScrollRef(scrollRef: Scrollbars) {
handleScrollRef(scrollRef: Scrollbars) {
if (scrollRef) {
scrollRef.scrollToBottom()
}
}

private getMessagePreviewForScreenReader(props) {
getMessagePreviewForScreenReader(props) {
/* Show the first 44 characters from the message, reasons:
- as NVDA splits it into 2 lines if more is shown
- for announcements feature, messaging team went with 44 characters but that was not based on loc issues but some UI real estate issue. */
Expand Down
8 changes: 4 additions & 4 deletions docs/src/prototypes/chatPane/chatPaneHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface ChatPaneHeaderProps {
}

class ChatPaneHeader extends React.PureComponent<ChatPaneHeaderProps> {
public render() {
render() {
return (
<Flex column>
<Flex.Item>{this.renderBanner()}</Flex.Item>
Expand All @@ -19,7 +19,7 @@ class ChatPaneHeader extends React.PureComponent<ChatPaneHeaderProps> {
)
}

private renderBanner(): React.ReactElement {
renderBanner(): React.ReactElement {
return (
<Segment
content={
Expand All @@ -41,7 +41,7 @@ class ChatPaneHeader extends React.PureComponent<ChatPaneHeaderProps> {
)
}

private renderMainArea(): React.ReactElement {
renderMainArea(): React.ReactElement {
const { chat } = this.props

return (
Expand Down Expand Up @@ -74,7 +74,7 @@ class ChatPaneHeader extends React.PureComponent<ChatPaneHeaderProps> {
)
}

private renderHeaderButtons(): React.ReactElement {
renderHeaderButtons(): React.ReactElement {
return (
<div style={{ display: 'inline-flex' }}>
<Button.Group
Expand Down
10 changes: 5 additions & 5 deletions docs/src/prototypes/mentions/PortalAtCursorPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ export interface PortalAtCursorPositionProps {
}

export class PortalAtCursorPosition extends React.Component<PortalAtCursorPositionProps> {
private mountNodeInstance: HTMLElement = null
mountNodeInstance: HTMLElement = null

static defaultProps = {
mountNodeId: 'portal-at-cursor-position',
}

public componentWillUnmount() {
componentWillUnmount() {
this.removeMountNode()
}

public render() {
render() {
const { children, open } = this.props

this.setupMountNode()
Expand All @@ -27,7 +27,7 @@ export class PortalAtCursorPosition extends React.Component<PortalAtCursorPositi
: null
}

private setupMountNode = () => {
setupMountNode = () => {
const { mountNodeId, open } = this.props

if (open) {
Expand All @@ -37,7 +37,7 @@ export class PortalAtCursorPosition extends React.Component<PortalAtCursorPositi
}
}

private removeMountNode = () => {
removeMountNode = () => {
if (this.mountNodeInstance) {
removeElement(this.mountNodeInstance)
this.mountNodeInstance = null
Expand Down
5 changes: 5 additions & 0 deletions packages/eslint-plugin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
rules: {
'no-visibility-modifiers': require('./rules/no-visibility-modifiers'),
},
}
14 changes: 14 additions & 0 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@stardust-ui/eslint-plugin",
"version": "0.31.0",
"dependencies": {
"@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/experimental-utils": "^1.9.0"
},
"files": [
"rules"
],
"publishConfig": {
"access": "public"
}
}
Loading