Skip to content
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

chore(eslint): enable consistent types import/exports #672

Merged
merged 3 commits into from
Oct 25, 2021
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
76 changes: 42 additions & 34 deletions .eslintrc.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ module.exports = {
parserOptions: {
ecmaFeatures: {
jsx: true,
globalReturn: false,
},
ecmaVersion: 12,
sourceType: 'module',
ecmaVersion: 2020,
project: ['tsconfig.json'],
},
settings: {
react: {
Expand Down Expand Up @@ -41,62 +42,69 @@ module.exports = {
},
rules: {
'linebreak-style': ['error', 'unix'],
'import/default': 'off',
'import/no-named-as-default-member': 'off',
'import/no-named-as-default': 'off',
'import/order': [
'error',
{
groups: [
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
'object',
],
alphabetize: { order: 'asc', caseInsensitive: true },
},
],
'no-empty-function': 'off',
'@typescript-eslint/no-empty-function': [
'error',
{ allow: ['private-constructors'] },
],
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
},
overrides: [
{
files: ['*.{ts,tsx}'],
rules: {
'@typescript-eslint/consistent-type-exports': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'no-empty-function': 'off',
'@typescript-eslint/no-empty-function': [
'error',
{ allow: ['private-constructors'] },
],
'@typescript-eslint/no-unused-vars': [
'warn',
{ argsIgnorePattern: '^_' },
],
'import/default': 'off',
'import/no-named-as-default-member': 'off',
'import/no-named-as-default': 'off',
'import/order': [
'error',
{
groups: [
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
'object',
],
alphabetize: { order: 'asc', caseInsensitive: true },
},
],
},
},
{
// For performance run sonarjs/recommended on regular code, not test files.
files: ['**/*.[jt]s?(x)'],
excludedFiles: [
'**/__tests__/**/*.[jt]s?(x)',
'**/?(*.)+(test).[jt]s?(x)',
],
files: ['**/*.{ts,tsx}'],
excludedFiles: ['**/__tests__/**/*.{ts,tsx}'],
extends: ['plugin:sonarjs/recommended'],
rules: {
'sonarjs/no-nested-template-literals': 'off',
},
},
{
// For performance run jest/recommended on test files, not regular code
files: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(test).[jt]s?(x)'],
files: ['**/__tests__/**/*.{ts,tsx}', '**/?(*.)+(test).{ts,tsx}'],
extends: ['plugin:jest/recommended'],
rules: {
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-object-literal-type-assertion': 'off',
'@typescript-eslint/no-empty-function': 'off',
},
},

{
files: ['*.config.js', '**/jest/**/*.js'],
files: ['*.js'],
parser: 'espree',
parserOptions: {
ecmaVersion: 2020,
},
rules: {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
Expand Down
19 changes: 3 additions & 16 deletions apps/blog-app/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// See ../../.eslintrc.base.js
module.exports = {
root: true,
ignorePatterns: ['node_modules/*', '.next'],
Expand Down Expand Up @@ -30,25 +31,11 @@ module.exports = {
overrides: [
{
// For performance run jest/recommended on test files, not regular code
files: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(test).[jt]s?(x)'],
files: ['**/*.test.{ts,tsx}'],
extends: ['plugin:testing-library/react'],
},
{
files: ['next.config.js'],
parser: 'espree',
parserOptions: {
ecmaVersion: 2020,
},
rules: {
'import/order': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
},
},
{
files: ['src/pages/**/*.ts', 'src/pages/**/*.tsx'],
files: ['src/pages/**/*.{ts,tsx}'],
rules: {
'@typescript-eslint/explicit-module-boundary-types': 'off',
'react/display-name': 'off',
Expand Down
3 changes: 2 additions & 1 deletion apps/blog-app/config/jest/__mocks__/react-svgr-mock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* @link {https://github.com/gregberge/svgr/issues/83#issuecomment-785996587|Config that actually works}
*/

import React, { SVGProps } from 'react';
import type { SVGProps } from 'react';
import React from 'react';

const SvgrMock = React.forwardRef<SVGSVGElement, SVGProps<SVGSVGElement>>(
(props, ref) => <svg ref={ref} {...props} />
Expand Down
2 changes: 1 addition & 1 deletion apps/blog-app/config/jest/test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @see https://testing-library.com/docs/react-testing-library/setup#configuring-jest-with-test-utils
*/
import { render } from '@testing-library/react';
import React from 'react';
import type React from 'react';
import { AppTestProviders } from './app-test-providers';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
2 changes: 1 addition & 1 deletion apps/blog-app/src/app-providers.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC } from 'react';
import type { FC } from 'react';

/**
* Set your global app-providers (i.e: redux, react-query,...) here
Expand Down
2 changes: 1 addition & 1 deletion apps/blog-app/src/components/layout/main-footer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC } from 'react';
import type { FC } from 'react';

type Props = {
children?: never;
Expand Down
2 changes: 1 addition & 1 deletion apps/blog-app/src/components/layout/main-header.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC } from 'react';
import type { FC } from 'react';

type Props = {
children?: never;
Expand Down
2 changes: 1 addition & 1 deletion apps/blog-app/src/components/layout/main-layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC } from 'react';
import type { FC } from 'react';
import { MainFooter } from '@/components/layout/main-footer';
import { MainHeader } from '@/components/layout/main-header';

Expand Down
3 changes: 2 additions & 1 deletion apps/blog-app/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { sayHello } from '@your-org/core-lib';
import { NextSeo } from 'next-seo';
import Image from 'next/image';
import { getPosts, Post } from '../data/blog';
import type { Post } from '../data/blog';
import { getPosts } from '../data/blog';
import { MainLayout } from '@/components/layout/main-layout';

type Props = {
Expand Down
2 changes: 1 addition & 1 deletion apps/blog-app/src/types.d/react-svgr.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

declare module '*.svg' {
import React from 'react';
import type React from 'react';
const SVG: React.VFC<React.SVGProps<SVGSVGElement>>;
export default SVG;
}
19 changes: 3 additions & 16 deletions apps/web-app/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// See ../../.eslintrc.base.js
module.exports = {
root: true,
ignorePatterns: ['node_modules/*', '.next'],
Expand Down Expand Up @@ -30,25 +31,11 @@ module.exports = {
overrides: [
{
// For performance run jest/recommended on test files, not regular code
files: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(test).[jt]s?(x)'],
files: ['**/*.test.{ts,tsx}'],
extends: ['plugin:testing-library/react'],
},
{
files: ['next.config.js', '*.theme.js'],
parser: 'espree',
parserOptions: {
ecmaVersion: 2020,
},
rules: {
'import/order': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
},
},
{
files: ['src/pages/**/*.ts', 'src/pages/**/*.tsx'],
files: ['src/pages/**/*.{ts,tsx}'],
rules: {
'@typescript-eslint/explicit-module-boundary-types': 'off',
'react/display-name': 'off',
Expand Down
3 changes: 2 additions & 1 deletion apps/web-app/config/jest/__mocks__/react-svgr-mock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* @link {https://github.com/gregberge/svgr/issues/83#issuecomment-785996587|Config that actually works}
*/

import React, { SVGProps } from 'react';
import type { SVGProps } from 'react';
import React from 'react';

const SvgrMock = React.forwardRef<SVGSVGElement, SVGProps<SVGSVGElement>>(
(props, ref) => <svg ref={ref} {...props} />
Expand Down
2 changes: 1 addition & 1 deletion apps/web-app/config/jest/test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @see https://testing-library.com/docs/react-testing-library/setup#configuring-jest-with-test-utils
*/
import { render } from '@testing-library/react';
import React from 'react';
import type React from 'react';
import { AppTestProviders } from './app-test-providers';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
5 changes: 3 additions & 2 deletions apps/web-app/src/app-providers.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CacheProvider, EmotionCache } from '@emotion/react';
import type { EmotionCache } from '@emotion/react';
import { CacheProvider } from '@emotion/react';
import { ThemeProvider as MuiThemeProvider } from '@mui/material';
import { FC } from 'react';
import type { FC } from 'react';

import { QueryClient, QueryClientProvider } from 'react-query';
import { createEmotionCache } from '@/core/nextjs/create-emotion-cache';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PrismaClientDbMain } from '@your-org/db-main-prisma';
import type { PrismaClientDbMain } from '@your-org/db-main-prisma';
import { prismaClient } from '@/backend/config/container.config';

export type GraphqlSdlContext = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { gql } from 'apollo-server-micro';
import { GraphqlSdlContext } from './graphql-sdl-context';
import type { GraphqlSdlContext } from './graphql-sdl-context';
import { PoemRepositorySsr } from '@/backend/api/rest/poem-repository.ssr';

const typeDefs = gql`
Expand Down
4 changes: 2 additions & 2 deletions apps/web-app/src/backend/api/rest/poem-repository.ssr.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InternalServerError } from '@tsed/exceptions';
import { UnPromisify } from '@your-org/core-lib';
import { PrismaClientDbMain } from '@your-org/db-main-prisma';
import type { UnPromisify } from '@your-org/core-lib';
import type { PrismaClientDbMain } from '@your-org/db-main-prisma';

export type GetPoems = UnPromisify<
ReturnType<typeof PoemRepositorySsr['prototype']['getPoems']>
Expand Down
5 changes: 3 additions & 2 deletions apps/web-app/src/backend/api/rest/post-repository.ssr.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { InternalServerError, NotFound } from '@tsed/exceptions';
import { Asserts, UnPromisify } from '@your-org/core-lib';
import { PrismaClientDbMain } from '@your-org/db-main-prisma';
import type { UnPromisify } from '@your-org/core-lib';
import { Asserts } from '@your-org/core-lib';
import type { PrismaClientDbMain } from '@your-org/db-main-prisma';

export type GetPosts = UnPromisify<
ReturnType<typeof PostRepositorySsr['prototype']['getPosts']>
Expand Down
2 changes: 1 addition & 1 deletion apps/web-app/src/core/i18n/get-server-side-translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Utility wrapper to prefer over calling serveSideTranslations directly
* if you need to customize globally
*/
import { SSRConfig, UserConfig } from 'next-i18next';
import type { SSRConfig, UserConfig } from 'next-i18next';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import nextI18nextConfig from '../../../next-i18next.config';

Expand Down
2 changes: 1 addition & 1 deletion apps/web-app/src/core/i18n/i18n-namespaces.type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CustomTypeOptions } from 'react-i18next';
import type { CustomTypeOptions } from 'react-i18next';

export type I18nNamespace = keyof CustomTypeOptions['resources'];

Expand Down
6 changes: 2 additions & 4 deletions apps/web-app/src/features/demo/api/fetch-poems-ky.api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
isJsonApiSuccessResponse,
JsonApiResponse,
} from '@your-org/core-lib/api/json-api';
import type { JsonApiResponse } from '@your-org/core-lib/api/json-api';
import { isJsonApiSuccessResponse } from '@your-org/core-lib/api/json-api';
import type { GetPoems } from '@/backend/api/rest/poem-repository.ssr';
import { ky } from '@/config/ky';

Expand Down
6 changes: 2 additions & 4 deletions apps/web-app/src/features/demo/api/fetch-posts-axios.api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
isJsonApiSuccessResponse,
JsonApiResponse,
} from '@your-org/core-lib/api/json-api';
import type { JsonApiResponse } from '@your-org/core-lib/api/json-api';
import { isJsonApiSuccessResponse } from '@your-org/core-lib/api/json-api';
import axios from 'axios';
import type { GetPosts } from '@/backend/api/rest/post-repository.ssr';

Expand Down
6 changes: 2 additions & 4 deletions apps/web-app/src/features/demo/api/fetch-posts-ky.api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
isJsonApiSuccessResponse,
JsonApiResponse,
} from '@your-org/core-lib/api/json-api';
import type { JsonApiResponse } from '@your-org/core-lib/api/json-api';
import { isJsonApiSuccessResponse } from '@your-org/core-lib/api/json-api';
import type { GetPosts } from '@/backend/api/rest/post-repository.ssr';
import { ky } from '@/config/ky';

Expand Down
6 changes: 4 additions & 2 deletions apps/web-app/src/features/demo/blocks/demo-mui.block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import CardHeader from '@mui/material/CardHeader';
import CardMedia from '@mui/material/CardMedia';
import Collapse from '@mui/material/Collapse';
import { red } from '@mui/material/colors';
import IconButton, { IconButtonProps } from '@mui/material/IconButton';
import type { IconButtonProps } from '@mui/material/IconButton';
import IconButton from '@mui/material/IconButton';
import { styled } from '@mui/material/styles';
import Typography from '@mui/material/Typography';
import { FC, useState } from 'react';
import type { FC } from 'react';
import { useState } from 'react';

type NoChildrenProps = {
children?: never;
Expand Down
2 changes: 1 addition & 1 deletion apps/web-app/src/features/demo/components/poem-card.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GetPoems } from '@/backend/api/rest/poem-repository.ssr';
import type { GetPoems } from '@/backend/api/rest/poem-repository.ssr';

type Props = {
img: GetPoems[0]['image'];
Expand Down
2 changes: 1 addition & 1 deletion apps/web-app/src/features/demo/components/poem-grid.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ArrayUtils } from '@your-org/core-lib';
import { PoemCard } from './poem-card';
import { GetPoems } from '@/backend/api/rest/poem-repository.ssr';
import type { GetPoems } from '@/backend/api/rest/poem-repository.ssr';

const waterImages = new Array(25).fill('').map((img, idx) => {
const index = String(idx + 1).padStart(2, '0');
Expand Down
2 changes: 1 addition & 1 deletion apps/web-app/src/features/demo/demo.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { I18nActiveNamespaces } from '@/core/i18n/i18n-namespaces.type';
import type { I18nActiveNamespaces } from '@/core/i18n/i18n-namespaces.type';

export type DemoConfig = {
// Define installed namespaces in the type here
Expand Down
2 changes: 1 addition & 1 deletion apps/web-app/src/features/home/home.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { I18nActiveNamespaces } from '@/core/i18n/i18n-namespaces.type';
import type { I18nActiveNamespaces } from '@/core/i18n/i18n-namespaces.type';

export type HomeConfig = {
// Define installed namespaces in the type here
Expand Down
2 changes: 1 addition & 1 deletion apps/web-app/src/pages/404.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { GetStaticPropsContext, InferGetStaticPropsType } from 'next';
import { useTranslation } from 'react-i18next';
import { getServerSideTranslations } from '@/core/i18n/get-server-side-translations';
import { I18nActiveNamespaces } from '@/core/i18n/i18n-namespaces.type';
import type { I18nActiveNamespaces } from '@/core/i18n/i18n-namespaces.type';

// To allow full typechecks in keys.
const i18nNamespaces: I18nActiveNamespaces<'system'> = ['system'];
Expand Down
Loading