Skip to content

Commit

Permalink
Merge pull request #354 from belgattitude/improved-eslint
Browse files Browse the repository at this point in the history
Improved eslint config
  • Loading branch information
belgattitude authored Sep 2, 2021
2 parents bcbaab0 + 84109ad commit 4b18254
Show file tree
Hide file tree
Showing 60 changed files with 349 additions and 304 deletions.
9 changes: 9 additions & 0 deletions .changeset/plenty-socks-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'blog-app': patch
'web-app': patch
'@your-org/core-lib': patch
'@your-org/db-main-prisma': patch
'@your-org/ui-lib': patch
---

Improve eslint config and add eslint-plugin-import
90 changes: 90 additions & 0 deletions .eslintrc.base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
module.exports = {
root: true,
env: {
node: true,
es6: true,
},
ignorePatterns: ['node_modules/*'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 12,
sourceType: 'module',
},
settings: {
react: {
version: 'detect',
},
'import/resolver': {
typescript: {},
},
},
extends: [
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'plugin:jest/recommended',
'plugin:sonarjs/recommended',
],
globals: {
context: 'readonly',
cy: 'readonly',
assert: 'readonly',
Cypress: 'readonly',
},
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: ['*.config.js', '**/jest/**/*.js'],
parser: 'espree',
parserOptions: {
ecmaVersion: 2020,
},
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'sonarjs/no-duplicate-string': 'off',
'sonarjs/no-all-duplicated-branches': 'off',
},
},
{
files: ['*.test.ts', '*.test.tsx'],
rules: {
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-object-literal-type-assertion': 'off',
'@typescript-eslint/no-empty-function': 'off',
},
},
],
};
75 changes: 0 additions & 75 deletions .eslintrc.base.json

This file was deleted.

4 changes: 0 additions & 4 deletions apps/blog-app/.eslintignore

This file was deleted.

63 changes: 63 additions & 0 deletions apps/blog-app/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
module.exports = {
root: true,
ignorePatterns: ['node_modules/*', '.next'],
extends: [
'../../.eslintrc.base.js',
// Add specific rules for react and nextjs
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:jsx-a11y/recommended',
'plugin:@next/next/recommended',
'plugin:testing-library/react',
],
env: {
browser: true,
es6: true,
node: true,
},
rules: {
'react/prop-types': 'off',
'react/react-in-jsx-scope': 'off',
'jsx-a11y/anchor-is-valid': 'off',
'react/no-unescaped-entities': 'off',

// next/image might not be yet a good move as of NextJs v11.
// https://github.com/vercel/next.js/discussions/16832
'@next/next/no-img-element': 'off',
},
overrides: [
{
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'],
rules: {
'@typescript-eslint/explicit-module-boundary-types': 'off',
},
},
{
files: ['src/backend/api/**/*.ts'],
rules: {
'@typescript-eslint/explicit-module-boundary-types': 'off',
},
},
{
files: ['config/jest/test-utils.tsx'],
rules: {
'@typescript-eslint/explicit-module-boundary-types': 'off',
'import/export': 'off',
},
},
],
};
49 changes: 0 additions & 49 deletions apps/blog-app/.eslintrc.json

This file was deleted.

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 @@ -2,8 +2,8 @@
* Automatically add app-providers
* @see https://testing-library.com/docs/react-testing-library/setup#configuring-jest-with-test-utils
*/
import React from 'react';
import { render } from '@testing-library/react';
import 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/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// @ts-check
'use strict';

const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { defaults: tsPreset } = require('ts-jest/presets');
const { pathsToModuleNameMapper } = require('ts-jest/utils');

const { compilerOptions: baseTsConfig } = require('./tsconfig.json');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render, screen } from '@/test-utils';
import { MainLayout } from '@/components/layout/main-layout';
import { render, screen } from '@/test-utils';

describe('Layout tests', () => {
it('should render children', async () => {
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,6 +1,6 @@
import { FC } from 'react';
import { MainHeader } from '@/components/layout/main-header';
import { MainFooter } from '@/components/layout/main-footer';
import { MainHeader } from '@/components/layout/main-header';

export const MainLayout: FC = (props) => {
const { children } = props;
Expand Down
4 changes: 2 additions & 2 deletions apps/blog-app/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +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 { MainLayout } from '@/components/layout/main-layout';
import Image from 'next/image';
import { NextSeo } from 'next-seo';

type Props = {
posts: Post[];
Expand Down
2 changes: 1 addition & 1 deletion apps/blog-app/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const defaultTheme = require('tailwindcss/defaultTheme');
const colors = require('tailwindcss/colors');
const defaultTheme = require('tailwindcss/defaultTheme');

module.exports = {
mode: 'jit',
Expand Down
4 changes: 0 additions & 4 deletions apps/web-app/.eslintignore

This file was deleted.

Loading

2 comments on commit 4b18254

@vercel
Copy link

@vercel vercel bot commented on 4b18254 Sep 2, 2021

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 4b18254 Sep 2, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.