Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

chore: eslint migration #186

Merged
merged 17 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from 16 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 .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pkg/**/*
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ["@carforyou/eslint-config/react"],
}
15 changes: 6 additions & 9 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
/* tslint:disable:object-literal-sort-keys */
module.exports = {
globals: {
"ts-jest": {
diagnostics: { warnOnly: true }
}
diagnostics: { warnOnly: true },
},
},
moduleFileExtensions: ["js", "ts", "tsx", "node"],
moduleNameMapper: {
"assets/(.*).(jpe?g|png|gif|ico|svg)$":
"<rootDir>/src/__mocks__/fileMock.js",
"\\.(css|less)$": "<rootDir>/src/__mocks__/styleMock.js"
"\\.(css|less)$": "<rootDir>/src/__mocks__/styleMock.js",
},
setupFiles: [
"<rootDir>/src/__tests__/setup/setupGlobalMocks.ts"
],
setupFiles: ["<rootDir>/src/__tests__/setup/setupGlobalMocks.ts"],
testMatch: ["**/__tests__/**/*.test.ts?(x)"],
transform: {
"\\.tsx?$": "ts-jest"
}
"\\.tsx?$": "ts-jest",
},
}
2,303 changes: 1,909 additions & 394 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"version": "npm run build",
"dev": "npm run build:tailwind && start-storybook -p 6006",
"test": "jest",
"lint": "tslint --project tsconfig.json",
"format": "tslint --project tsconfig.json --fix",
"lint": "eslint --ext ts,js,tsx,jsx,json .",
"format": "npm run lint -- --fix",
"build": "npm run build:tailwind && pika build",
"build:tailwind": "tsc --project tsconfig.tailwind.json",
"build:storybook": "npm run build:tailwind && build-storybook",
Expand Down Expand Up @@ -39,9 +39,9 @@
"use-deep-compare-effect": "^1.3.0"
},
"devDependencies": {
"@babel/core": "^7.8.3",
"@babel/core": "^7.8.4",
"@carforyou/eslint-config": "1.1.0-initial-rules-ca8a1992a789bb4c88f8f9a642c9c867859b13b9.6",
"@carforyou/pika-plugin-build-standalone-node": "^1.0.0",
"@carforyou/tslint-rules": "^3.0.0",
"@percy/storybook": "^3.2.0",
"@pika/pack": "^0.5.0",
"@pika/plugin-build-web": "^0.9.0",
Expand All @@ -63,21 +63,23 @@
"@types/react-paginate": "^6.2.1",
"@zeit/next-typescript": "^1.1.1",
"awesome-typescript-loader": "^5.2.1",
"eslint": "^6.8.0",
"eslint-plugin-prettier": "^3.1.3",
"jest": "^25.1.0",
"marked": "^1.0.0",
"marked-terminal": "^4.1.0",
"postcss-easy-import": "^3.0.0",
"postcss-loader": "^3.0.0",
"prettier": "^2.0.5",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-docgen-typescript-loader": "^3.6.0",
"react-dom": "^16.12.0",
"react-test-renderer": "^16.12.0",
"semantic-release": "^17.0.0",
"svgo": "^1.3.2",
"tailwindcss": "^1.2.0",
"ts-jest": "^25.0.0",
"tslint": "^5.20.1",
"tslint": "^6.1.2",
"typescript": "^3.7.5"
},
"@pika/pack": {
Expand Down
6 changes: 3 additions & 3 deletions release.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module.exports = {
"master",
{
name: "!(+([0-9])?(.{+([0-9]),x}).x|master)",
prerelease: "${ name }" + `-${process.env.CIRCLE_SHA1}`
}
prerelease: "${ name }" + `-${process.env.CIRCLE_SHA1}`,
},
],
pkgRoot: "pkg"
pkgRoot: "pkg",
}
12 changes: 6 additions & 6 deletions src/__tests__/setup/setupGlobalMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ window.matchMedia =
window.matchMedia ||
(() => {
return {
addListener: () => {}, // tslint:disable-line: no-empty
addListener: jest.fn(),
matches: false,
removeListener: () => {}, // tslint:disable-line: no-empty
removeListener: jest.fn(),
media: "test",
onchange: () => {}, // tslint:disable-line: no-empty
addEventListener: () => {}, // tslint:disable-line: no-empty
removeEventListener: () => {}, // tslint:disable-line: no-empty
dispatchEvent: () => true, // tslint:disable-line: no-empty
onchange: jest.fn(),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: () => true,
}
})

Expand Down
2 changes: 1 addition & 1 deletion src/components/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface CheckboxProps {
disabled?: boolean
error?: string
renderLabel?: () => JSX.Element
onChange?: (e: ChangeEvent<any>) => void
onChange?: (e: ChangeEvent<HTMLInputElement>) => void
}

interface PositionedLabelProps extends CheckboxProps {
Expand Down
2 changes: 1 addition & 1 deletion src/components/dropdown/buttonToggle.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactChild, FC, ReactElement } from "react"
import React, { ReactChild, ReactElement } from "react"

interface Props<T> {
placeholder?: string
Expand Down
2 changes: 1 addition & 1 deletion src/components/dropdown/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class Menu<T> extends Component<Props<T>> {
)

return (
// tslint:disable-next-line:jsx-key
// eslint-disable-next-line react/jsx-key
Averethel marked this conversation as resolved.
Show resolved Hide resolved
<li
{...getItemProps({
"data-testid": item.name,
Expand Down
2 changes: 1 addition & 1 deletion src/components/dropdown/withAutosuggest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const filterOptions = (noResults) => (allOptions, text) => {
return allOptions
}

const specialChars = /[-\/\\^$*+?.()|[\]{}]/g
const specialChars = /[-/\\^$*+?.()|[\]{}]/g
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this really the same regex without the escaping backslash?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's an unnecessary escape character according to the linter

const cleanedText = text.replace(specialChars, "\\$&")
const regex = new RegExp(cleanedText, "i")
const startsWith = new RegExp(`^${cleanedText}`, "i")
Expand Down
7 changes: 4 additions & 3 deletions src/components/input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ interface InputProps {
onChange: <T extends { target: { name: string; value: string | number } }>(
e: T
) => void
onBlur?: (e: FocusEvent<any>) => void
onKeyDown?: (e: KeyboardEvent<any>) => void
onFocus?: (e: FocusEvent<any>) => void
onBlur?: (e: FocusEvent) => void
onKeyDown?: (e: KeyboardEvent) => void
onFocus?: (e: FocusEvent) => void
step?: number
min?: number
max?: number
Expand Down Expand Up @@ -93,6 +93,7 @@ const Input = forwardRef<HTMLInputElement, Props>(
value={value || ""}
placeholder={placeholder || ""}
className={classNames("w-12/12", className, {
// eslint-disable-next-line @typescript-eslint/naming-convention
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the plugin not in the latest version or does the variable set not cover block modifiers in the BEM convention?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our BEM convention is a mixture of camelCase and snake_case. By default, you cannot mix cases. What we could do is to write a custom regexp to support our BEM syntax...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh... that's a pity

(I don't have a valuable comment to make)

input_withClearButton: hasClearButton,
"floatingLabel-input": labelProps.floating,
})}
Expand Down
4 changes: 1 addition & 3 deletions src/components/input/inputField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ interface Props extends InputHTMLAttributes<HTMLInputElement> {
disabled?: boolean
required?: boolean
onChange?: (e: { target: { value: string | number } }) => void
onBlur?: (e: FocusEvent<any>) => void
onBlur?: (e: FocusEvent) => void
debounce?: number
}

Expand Down Expand Up @@ -93,15 +93,13 @@ const InputField = forwardRef<HTMLInputElement, Props>(
className={className}
inputMode={mode !== "text" ? mode : null}
onKeyDown={(e) => {
// tslint:disable:no-unused-expression
mode === "numeric"
? validateNumber(e)
: mode === "decimal"
? validateDecimal(e)
: null

onKeyDown && onKeyDown(e)
// tslint:enable:no-unused-expression
}}
onChange={debounceCallback(onChange, debounce)}
onBlur={onBlur}
Expand Down
1 change: 1 addition & 0 deletions src/components/intercom/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const loadIntercom = (settings) => {
if (!window.Intercom) {
;((w, d, id, s, _x) => {
function i() {
// eslint-disable-next-line prefer-rest-params
i.c(arguments)
}
i.q = []
Expand Down
2 changes: 1 addition & 1 deletion src/components/pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface Props {
previousLabel: string
nextLabel: string
rangePageLabel: string
onPageChange: (data: any) => void
onPageChange: (data) => void
forcePage: number
query?: object
pageLinkBuilder?: (page: number, params: object) => string
Expand Down
2 changes: 1 addition & 1 deletion src/components/radioButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface Props<T> {
error?: string
renderLabel?: () => JSX.Element
labelPosition?: "left" | "right"
onChange?: (e: ChangeEvent<any>) => void
onChange?: (e: ChangeEvent<HTMLInputElement>) => void
}

function RadioButton<T>({
Expand Down
2 changes: 1 addition & 1 deletion src/components/segmentedControl/button.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, ReactNode, createElement } from "react"
import { FC, ReactNode, createElement } from "react"
import classnames from "classnames"

import { wrapLink } from "../../lib/buttonHelper"
Expand Down
4 changes: 4 additions & 0 deletions src/components/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ interface SimpleSelect<T> extends BaseProps<T> {

type Props<T> = AutosuggestSelect<T> | SimpleSelect<T>

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const Select = forwardRef<HTMLInputElement, Props<any>>(
(
{
Expand Down Expand Up @@ -178,6 +179,7 @@ const Select = forwardRef<HTMLInputElement, Props<any>>(
return {
select_open: showOpenedIcon && !selected,
select_closed: !isOpen && !selected,
// eslint-disable-next-line @typescript-eslint/naming-convention
select_withSearchIcon: showOpenedIcon && !selected && showSearchIcon,
}
}
Expand Down Expand Up @@ -211,9 +213,11 @@ const Select = forwardRef<HTMLInputElement, Props<any>>(
<>
{"withAutosuggest" in rest && rest.withAutosuggest ? (
<DropdownWithAutosuggest
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard to tell without looking into the code, perhaps we can change the way we pass the props or add form the props

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not find a way to add a type variable to existing constructs like forwardRef. This causes the any above and by consequence any here.

{...(dropdownProps as DropdownWithAutosuggestProps<any>)}
/>
) : (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
<Dropdown {...(dropdownProps as DropdownProps<any>)} />
)}
</>
Expand Down
2 changes: 1 addition & 1 deletion src/components/textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface Props {
disabled?: boolean
required?: boolean
onChange: (e: { target: { value: string } }) => void
onBlur: (e: FocusEvent<any>) => void
onBlur: (e: FocusEvent) => void
rows?: number
cols?: number
maxLength?: number
Expand Down
6 changes: 3 additions & 3 deletions src/lib/debounceHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
* @note: Currently only supports callbacks with a single parameter (for form input events)
*/
function debounce(
callback?: (event: any) => void,
callback?: (event) => void,
delay?: number
): (event: any) => void | undefined {
): (event) => void | undefined {
if (!callback || !delay) {
return callback
}
let timer
return (event: any): void => {
return (event): void => {
clearTimeout(timer)
timer = setTimeout(() => {
timer = null
Expand Down
2 changes: 1 addition & 1 deletion src/tailwind/defaultConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* tslint:disable:object-literal-sort-keys */
import TransformPlugin from "./plugins/transform"
/*
Tailwind - The Utility-First CSS Framework
Expand Down Expand Up @@ -594,5 +593,6 @@ export default {
transitionDuration: ["responsive", "hover"],
},
corePlugins: {},
// eslint-disable-next-line @typescript-eslint/no-var-requires
plugins: [TransformPlugin, require("tailwindcss-gradients")()],
}
3 changes: 2 additions & 1 deletion src/tailwind/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface TailwindConfig {
theme?: TailwindTheme
options?: { [key: string]: string | number | boolean }
modules?: { [key: string]: string[] }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
plugins?: any[]
}

Expand All @@ -49,7 +50,7 @@ const resolveConfig = (config) => {
}

for (const conf in config.theme) {
if (config.theme.hasOwnProperty(conf)) {
if (Object.prototype.hasOwnProperty.call(config.theme, conf)) {
theme[conf] =
typeof config.theme[conf] === "function"
? config.theme[conf](getKey)
Expand Down
Loading