Skip to content

Commit

Permalink
eslint and prettier setup
Browse files Browse the repository at this point in the history
  • Loading branch information
nishkohli96 committed Feb 1, 2024
1 parent a65022f commit d5df4c7
Show file tree
Hide file tree
Showing 41 changed files with 913 additions and 1,179 deletions.
3 changes: 2 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
npm run prettier
npm run lint
npm run prettier
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"singleAttributePerLine": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"trailingComma": "es5",
"useTabs": false
}
3 changes: 3 additions & 0 deletions apps/fastify-server/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['@nish1896']
}
1 change: 1 addition & 0 deletions apps/fastify-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"start:debug": "nest start --debug --watch",
"start:prod": "node build/main",
"test": "jest",
"lint": "eslint --fix .",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
Expand Down
4 changes: 1 addition & 3 deletions apps/fastify-server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { Module } from '@nestjs/common';
import { HomeModule } from './app/home/home.module';

@Module({
imports: [
HomeModule,
],
imports: [HomeModule],
controllers: [],
providers: [],
})
Expand Down
4 changes: 1 addition & 3 deletions apps/fastify-server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ async function bootstrap() {
ignoreTrailingSlash: true,
caseSensitive: false,
}),
{
logger: ['error', 'warn'],
},
{ logger: ['error', 'warn'] },
);

/**
Expand Down
16 changes: 6 additions & 10 deletions apps/fastify-server/test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ describe('AppController (e2e)', () => {
let app: INestApplication;

beforeAll(async () => {
const moduleFixture = await Test.createTestingModule({
imports: [AppModule],
}).compile();
const moduleFixture = await Test.createTestingModule({ imports: [AppModule] }).compile();

app = moduleFixture.createNestApplication();
await app.init();
Expand All @@ -19,10 +17,8 @@ describe('AppController (e2e)', () => {
await app.close();
});

it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!');
});
});
it('/ (GET)', () => request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!'));
});
4 changes: 4 additions & 0 deletions apps/frontend/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
extends: ['@nish1896']
}

22 changes: 0 additions & 22 deletions apps/frontend/.eslintrc.json

This file was deleted.

2 changes: 2 additions & 0 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"web-vitals": "^3.5.2"
},
"devDependencies": {
"@nish1896/eslint-config": "^1.0.3",
"@testing-library/jest-dom": "^6.4.0",
"@testing-library/react": "^14.2.0",
"@testing-library/user-event": "^14.5.2",
Expand All @@ -38,6 +39,7 @@
"@types/react-redux": "^7.1.33",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"eslint": "^8.56.0",
"typescript": "^5.3.3"
},
"browserslist": {
Expand Down
12 changes: 6 additions & 6 deletions apps/frontend/src/assets/styles/palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export const LightThemePalette = {
divider: '#9e9e9e',
background: {
default: '#FFFFFF',
paper: '#e0dfdc'
paper: '#e0dfdc',
},
text: {
primary: '#121212',
secondary: '#4C4C4C'
}
secondary: '#4C4C4C',
},
};

export const DarkThemePalette = {
Expand All @@ -31,10 +31,10 @@ export const DarkThemePalette = {
divider: '#4c4c4c',
background: {
default: '#1a1919',
paper: '#2b2b2b'
paper: '#2b2b2b',
},
text: {
primary: '#f8f7ff',
secondary: '#f6e4df'
}
secondary: '#f6e4df',
},
};
6 changes: 3 additions & 3 deletions apps/frontend/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ const root = createRoot(container!);

root.render(
<React.StrictMode>
<Provider store={store}>
<Provider store={store}>
<PersistGate loading={''} persistor={persistor}>
<App />
</PersistGate>
<App />
</PersistGate>
</Provider>
</React.StrictMode>,
);
Expand Down
12 changes: 8 additions & 4 deletions apps/frontend/src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ const HomePage = () => {

return (
<div className="root">
<div style={{ margin: '10px 0px' }}>Hello from the HomePage.</div>
<div style={{ margin: '10px 0px' }}>Hello from the HomePage.</div>
<div style={{ margin: '10px 0px' }}>
<p>
This component exported from <b>@core/lib</b>
This component exported from
{' '}
<b>@core/lib</b>
</p>
<TextWithBadge text="Sample Badge Text" badgeVal={5} />
</div>
Expand All @@ -22,8 +24,10 @@ const HomePage = () => {
<Fragment>
{pokemonList?.length
? pokemonList?.map((pokemon, idx) => (
<Typography color='primary' key={idx}>{pokemon.name}</Typography>
))
<Typography color="primary" key={idx}>
{pokemon.name}
</Typography>
))
: 'Unable to fetch pokemons'}
</Fragment>
)}
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/src/redux-store/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './hooks';
export * from './reducers';
export * from './services';
export * from './store';
export * from './store';
2 changes: 1 addition & 1 deletion apps/frontend/src/redux-store/reducers/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './settings.slice';
export * from './settings.slice';
16 changes: 8 additions & 8 deletions apps/frontend/src/redux-store/reducers/settings.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ interface SettingsConfig {

export enum ThemeMode {
LIGHT = 'light',
DARK = 'dark'
DARK = 'dark',
}

const initialState: SettingsConfig = {
/* Uses system theme as default */
mode:
window.matchMedia &&
window.matchMedia('(prefers-color-scheme: dark)').matches
window.matchMedia
&& window.matchMedia('(prefers-color-scheme: dark)').matches
? ThemeMode.DARK
: ThemeMode.LIGHT
: ThemeMode.LIGHT,
};

export const settingsSlice = createSlice({
name: 'settings',
initialState,
reducers: {
toggleTheme: state => {
state.mode =
state.mode === ThemeMode.LIGHT ? ThemeMode.DARK : ThemeMode.LIGHT;
}
}
state.mode
= state.mode === ThemeMode.LIGHT ? ThemeMode.DARK : ThemeMode.LIGHT;
},
},
});

/* Actions */
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/src/redux-store/services/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './pokemon';
export * from './pokemon';
8 changes: 4 additions & 4 deletions apps/frontend/src/redux-store/services/pokemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const pokeApi = createApi({
prepareHeaders: headers => {
headers.set('X-some-KEY', 'API_KEY');
return headers;
}
},
}),
tagTypes: ['PokemonList'],
endpoints: builder => ({
Expand All @@ -25,9 +25,9 @@ export const pokeApi = createApi({
providesTags: ['PokemonList'],
transformResponse: (rawResult: PokeApiResult) => rawResult.results,
transformErrorResponse: (response: { status: string | number }) =>
response.status
})
})
response.status,
}),
}),
});

export const { useGetFirstNPokemonQuery } = pokeApi;
18 changes: 9 additions & 9 deletions apps/frontend/src/redux-store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,35 @@ import {
PAUSE,
PERSIST,
PURGE,
REGISTER
REGISTER,
} from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import { settingsSlice } from './reducers';
import { pokeApi } from './services';

const persistConfig = {
key: 'root',
storage
storage,
};

const rootReducer = combineReducers({
settings: settingsSlice.reducer
});
const rootReducer = combineReducers({ settings: settingsSlice.reducer });

const persistedReducer = persistReducer(persistConfig, rootReducer);

/* https://redux.js.org/style-guide/style-guide#do-not-put-non-serializable-values-in-state-or-actions */
export const store = configureStore({
reducer: {
appConfig: persistedReducer,
[pokeApi.reducerPath]: pokeApi.reducer
[pokeApi.reducerPath]: pokeApi.reducer,
},
middleware: getDefaultMiddleware =>
getDefaultMiddleware({
serializableCheck: {
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER]
}
}).concat([pokeApi.middleware])
ignoredActions: [
FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER,
],
},
}).concat([pokeApi.middleware]),
});

export const persistor = persistStore(store);
Expand Down
18 changes: 8 additions & 10 deletions apps/frontend/src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import RouteNames from './route-names';
import HomePage from 'pages/Home';
const Page404 = lazy(() => import('pages/Page404'));

const Routing: FC = () => {
return (
<BrowserRouter>
<Routes>
<Route path={RouteNames.home} element={<HomePage />} />
<Route path='*' element={<Page404 />} />
</Routes>
</BrowserRouter>
);
};
const Routing: FC = () => (
<BrowserRouter>
<Routes>
<Route path={RouteNames.home} element={<HomePage />} />
<Route path="*" element={<Page404 />} />
</Routes>
</BrowserRouter>
);

export default Routing;
8 changes: 3 additions & 5 deletions apps/frontend/src/routes/route-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
const RouteNames = {
home: '/',
account: {
rootPath: '/account',
subRoutes: {
manage: 'manage'
}
}
rootPath: '/account',
subRoutes: { manage: 'manage' },
},
};

export default RouteNames;
11 changes: 1 addition & 10 deletions apps/nestjs-server/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'@nish1896'
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
Expand Down
Loading

0 comments on commit d5df4c7

Please sign in to comment.