diff --git a/.eslintrc.yml b/.eslintrc.yml index 63cdb25b0b33a..ad85c6aaf16b6 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -1,7 +1,8 @@ extends: - - standard-jsx + - standard - standard-react - plugin:@typescript-eslint/recommended + - prettier - prettier/@typescript-eslint - prettier/standard - prettier/react @@ -39,7 +40,6 @@ overrides: es6: true rules: no-console: 'off' - '@typescript-eslint/no-var-requires': off - files: - '**/*.@(ts|tsx)' @@ -48,8 +48,13 @@ overrides: parser: '@typescript-eslint/parser' rules: # Argh. - '@typescript-eslint/explicit-function-return-type': 'off' + '@typescript-eslint/explicit-function-return-type': + ['error', { 'allowExpressions': true }] + '@typescript-eslint/no-empty-function': 'error' + '@typescript-eslint/no-var-requires': 'error' '@typescript-eslint/no-object-literal-type-assertion': 'off' + '@typescript-eslint/no-explicit-any': 'error' + '@typescript-eslint/ban-ts-ignore': 'off' - files: - core/**/*.ts @@ -113,9 +118,9 @@ rules: # Allow unused parameters. In callbacks, removing them seems to obscure # what the functions are doing. '@typescript-eslint/no-unused-vars': ['error', { 'args': 'none' }] - no-unused-vars: off + no-unused-vars: 'off' - '@typescript-eslint/no-var-requires': error + '@typescript-eslint/no-var-requires': 'off' # These should be disabled by eslint-config-prettier, but are not. no-extra-semi: 'off' @@ -163,6 +168,8 @@ rules: # Disable some from TypeScript. '@typescript-eslint/camelcase': off + '@typescript-eslint/explicit-function-return-type': 'off' + '@typescript-eslint/no-empty-function': 'off' react/jsx-sort-props: 'error' react-hooks/rules-of-hooks: 'error' diff --git a/core/base-service/coalesce.spec.js b/core/base-service/coalesce.spec.js index ed596d4276f0b..180f9e1e6aa1d 100644 --- a/core/base-service/coalesce.spec.js +++ b/core/base-service/coalesce.spec.js @@ -14,9 +14,9 @@ describe('coalesce', function() { given(null, [], {}).expect([]) given(null, undefined, 0, {}).expect(0) - const a = null, - c = 0, - d = 1 + const a = null + const c = 0 + const d = 1 let b given(a, b, c, d).expect(0) }) diff --git a/core/base-service/errors.js b/core/base-service/errors.js index 98c0043ebe2db..5bbd709089df1 100644 --- a/core/base-service/errors.js +++ b/core/base-service/errors.js @@ -56,6 +56,7 @@ class NotFound extends ShieldsRuntimeError { get name() { return 'NotFound' } + get defaultPrettyMessage() { return defaultNotFoundError } @@ -82,6 +83,7 @@ class InvalidResponse extends ShieldsRuntimeError { get name() { return 'InvalidResponse' } + get defaultPrettyMessage() { return 'invalid' } @@ -107,6 +109,7 @@ class Inaccessible extends ShieldsRuntimeError { get name() { return 'Inaccessible' } + get defaultPrettyMessage() { return 'inaccessible' } @@ -131,6 +134,7 @@ class ImproperlyConfigured extends ShieldsRuntimeError { get name() { return 'ImproperlyConfigured' } + get defaultPrettyMessage() { return 'improperly configured' } @@ -156,6 +160,7 @@ class InvalidParameter extends ShieldsRuntimeError { get name() { return 'InvalidParameter' } + get defaultPrettyMessage() { return 'invalid parameter' } @@ -180,6 +185,7 @@ class Deprecated extends ShieldsRuntimeError { get name() { return 'Deprecated' } + get defaultPrettyMessage() { return 'no longer available' } diff --git a/core/base-service/validate.js b/core/base-service/validate.js index c4db4104f469f..0bfc4a8773269 100644 --- a/core/base-service/validate.js +++ b/core/base-service/validate.js @@ -21,8 +21,8 @@ function validate( } const options = { abortEarly: false } if (allowAndStripUnknownKeys) { - options['allowUnknown'] = true - options['stripUnknown'] = true + options.allowUnknown = true + options.stripUnknown = true } const { error, value } = schema.validate(data, options) if (error) { diff --git a/core/server/monitor.js b/core/server/monitor.js index d62e2df573723..96ef183af760d 100644 --- a/core/server/monitor.js +++ b/core/server/monitor.js @@ -43,7 +43,7 @@ function setRoutes({ rateLimit }, { server, metricInstance }) { .split(/[/-]/) .slice(0, 3) .join('') - const referer = req.headers['referer'] + const referer = req.headers.referer if (ipRateLimit.isBanned(ip, req, res)) { metricInstance.noteRateLimitExceeded('ip') diff --git a/core/server/server.spec.js b/core/server/server.spec.js index bad8d9d6b129b..7150b7e36d8e5 100644 --- a/core/server/server.spec.js +++ b/core/server/server.spec.js @@ -24,7 +24,7 @@ describe('The server', function() { }) it('should allow strings for port', async function() { - //fixes #4391 - This allows the app to be run using iisnode, which uses a named pipe for the port. + // fixes #4391 - This allows the app to be run using iisnode, which uses a named pipe for the port. const pipeServer = createTestServer({ port: '\\\\.\\pipe\\9c137306-7c4d-461e-b7cf-5213a3939ad6', }) diff --git a/core/token-pooling/token-pool.js b/core/token-pooling/token-pool.js index 83e76771db450..5061c8dbf6c16 100644 --- a/core/token-pooling/token-pool.js +++ b/core/token-pooling/token-pool.js @@ -55,18 +55,23 @@ class Token { get id() { return this._id } + get data() { return this._data } + get usesRemaining() { return this._usesRemaining } + get nextReset() { return this._nextReset } + get isValid() { return this._isValid } + get isFrozen() { return this._isFrozen } diff --git a/frontend/components/badge-examples.tsx b/frontend/components/badge-examples.tsx index c10424b173dce..0a3229d5b8e4f 100644 --- a/frontend/components/badge-examples.tsx +++ b/frontend/components/badge-examples.tsx @@ -42,8 +42,8 @@ function Example({ onClick: (example: RenderableExample, isSuggestion: boolean) => void exampleData: RenderableExample isBadgeSuggestion: boolean -}) { - function handleClick() { +}): JSX.Element { + function handleClick(): void { onClick(exampleData, isBadgeSuggestion) } @@ -106,7 +106,7 @@ export function BadgeExamples({ areBadgeSuggestions: boolean baseUrl?: string onClick: (exampleData: RenderableExample, isSuggestion: boolean) => void -}) { +}): JSX.Element { return ( diff --git a/frontend/components/category-headings.tsx b/frontend/components/category-headings.tsx index 9cbcbb6a43a52..2f1d03c9a512a 100644 --- a/frontend/components/category-headings.tsx +++ b/frontend/components/category-headings.tsx @@ -12,7 +12,7 @@ export function CategoryHeading({ category: { id, name }, }: { category: Category -}) { +}): JSX.Element { return (

{name}

@@ -20,7 +20,11 @@ export function CategoryHeading({ ) } -export function CategoryHeadings({ categories }: { categories: Category[] }) { +export function CategoryHeadings({ + categories, +}: { + categories: Category[] +}): JSX.Element { return (
{categories.map(category => ( @@ -61,7 +65,11 @@ const StyledNav = styled.nav` } ` -export function CategoryNav({ categories }: { categories: Category[] }) { +export function CategoryNav({ + categories, +}: { + categories: Category[] +}): JSX.Element { return (
    diff --git a/frontend/components/common.tsx b/frontend/components/common.tsx index bd9d47b3b1fe5..60e2a78db7cbd 100644 --- a/frontend/components/common.tsx +++ b/frontend/components/common.tsx @@ -74,7 +74,7 @@ export function Badge({ height = '20px', clickable = false, ...rest -}: BadgeProps) { +}: BadgeProps): JSX.Element { return ( {src ? {alt} : nonBreakingSpace} diff --git a/frontend/components/customizer/builder-common.tsx b/frontend/components/customizer/builder-common.tsx index 907d78a160532..939184028728f 100644 --- a/frontend/components/customizer/builder-common.tsx +++ b/frontend/components/customizer/builder-common.tsx @@ -20,7 +20,7 @@ export function BuilderContainer({ children, }: { children: JSX.Element[] | JSX.Element -}) { +}): JSX.Element { return ( {children} diff --git a/frontend/components/customizer/copied-content-indicator.tsx b/frontend/components/customizer/copied-content-indicator.tsx index 42751944cef1c..560fe33872a6d 100644 --- a/frontend/components/customizer/copied-content-indicator.tsx +++ b/frontend/components/customizer/copied-content-indicator.tsx @@ -41,7 +41,7 @@ function _CopiedContentIndicator( children: JSX.Element | JSX.Element[] }, ref: React.Ref -) { +): JSX.Element { const [pose, setPose] = useState('hidden') useImperativeHandle(ref, () => ({ @@ -50,7 +50,7 @@ function _CopiedContentIndicator( }, })) - function handlePoseComplete() { + function handlePoseComplete(): void { if (pose === 'effectStart') { setPose('effectEnd') } else { diff --git a/frontend/components/customizer/customizer.tsx b/frontend/components/customizer/customizer.tsx index 5a6b1a19aecfa..fe925ec73b326 100644 --- a/frontend/components/customizer/customizer.tsx +++ b/frontend/components/customizer/customizer.tsx @@ -36,7 +36,7 @@ export default function Customizer({ initialStyle?: string isPrefilled: boolean link?: string -}) { +}): JSX.Element { // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/35572 // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/28884#issuecomment-471341041 const indicatorRef = useRef< @@ -48,12 +48,12 @@ export default function Customizer({ const [markup, setMarkup] = useState() const [message, setMessage] = useState() - function generateBuiltBadgeUrl() { + function generateBuiltBadgeUrl(): string { const suffix = queryString ? `?${queryString}` : '' return `${baseUrl || getBaseUrlFromWindowLocation()}${path}${suffix}` } - function renderLivePreview() { + function renderLivePreview(): JSX.Element { // There are some usability issues here. It would be better if the message // changed from a validation error to a loading message once the // parameters were filled in, and also switched back to loading when the @@ -75,7 +75,7 @@ export default function Customizer({ ) } - async function copyMarkup(markupFormat: MarkupFormat) { + async function copyMarkup(markupFormat: MarkupFormat): Promise { const builtBadgeUrl = generateBuiltBadgeUrl() const markup = generateMarkup({ badgeUrl: builtBadgeUrl, @@ -98,7 +98,7 @@ export default function Customizer({ } } - function renderMarkupAndLivePreview() { + function renderMarkupAndLivePreview(): JSX.Element { return (
    {renderLivePreview()} @@ -124,7 +124,7 @@ export default function Customizer({ }: { path: string isComplete: boolean - }) { + }): void { setPath(path) setPathIsComplete(isComplete) } @@ -135,7 +135,7 @@ export default function Customizer({ }: { queryString: string isComplete: boolean - }) { + }): void { setQueryString(queryString) } diff --git a/frontend/components/customizer/path-builder.tsx b/frontend/components/customizer/path-builder.tsx index 019a0d230572b..35b02f6be9aca 100644 --- a/frontend/components/customizer/path-builder.tsx +++ b/frontend/components/customizer/path-builder.tsx @@ -84,7 +84,7 @@ export function constructPath({ }: { tokens: Token[] namedParams: { [k: string]: string } -}) { +}): { path: string; isComplete: boolean } { let isComplete = true const path = tokens .map(token => { @@ -123,7 +123,7 @@ export default function PathBuilder({ isComplete: boolean }) => void isPrefilled: boolean -}) { +}): JSX.Element { const [tokens] = useState(() => parse(pattern)) const [namedParams, setNamedParams] = useState(() => isPrefilled @@ -150,7 +150,7 @@ export default function PathBuilder({ function handleTokenChange({ target: { name, value }, - }: ChangeEvent) { + }: ChangeEvent): void { setNamedParams({ ...namedParams, [name]: value, @@ -161,7 +161,7 @@ export default function PathBuilder({ literal: string, tokenIndex: number, pathContainsOnlyLiterals: boolean - ) { + ): JSX.Element { return ( -}) { +}): JSX.Element { return ( @@ -160,7 +160,7 @@ function BadgeOptionInput({ handleBadgeOptionChange: ChangeEventHandler< HTMLSelectElement | HTMLInputElement > -}) { +}): JSX.Element { if (name === 'style') { return (