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

Example with sonarjs eslint plugin #323

Merged
merged 5 commits into from
Aug 27, 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
9 changes: 9 additions & 0 deletions .changeset/popular-penguins-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'blog-app': minor
'web-app': minor
'@your-org/core-lib': minor
'@your-org/db-main-prisma': minor
'@your-org/ui-lib': minor
---

Example: eslint-plugin-sonarjs cause cause it desserves to belong here
13 changes: 9 additions & 4 deletions .eslintrc.base.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"root": true,
"extends": [
"plugin:sonarjs/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"plugin:jest/recommended"
Expand All @@ -10,7 +11,8 @@
"prettier",
"react-hooks",
"jest",
"jest-formatting"
"jest-formatting",
"sonarjs"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
Expand All @@ -30,8 +32,9 @@
"no-empty-function": "off",
"@typescript-eslint/no-empty-function": [
"error",
{ "allow": ["private-constructors", "decoratedFunctions"] }
]
{ "allow": ["private-constructors"] }
],
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }]
},
"overrides": [
{
Expand All @@ -55,7 +58,9 @@
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/explicit-module-boundary-types": "off"
"@typescript-eslint/explicit-module-boundary-types": "off",
"sonarjs/no-duplicate-string": "off",
"sonarjs/no-all-duplicated-branches": "off"
}
},
{
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ An example of base eslint configuration can be found in [./.eslint.base.json](./
and packages extends it in their own root folder, as an example see [./apps/web-app/.eslintrc.json](./apps/web-app/.eslintrc.json).
Prettier is included in eslint configuration as well as [eslint-config-next](https://nextjs.org/docs/basic-features/eslint) for nextjs apps.

For code complexity and deeper code analysis [sonarjs plugin](https://github.com/SonarSource/eslint-plugin-sonarjs) is activated.

### 5.2 Hooks / Lint-staged

Check the [.husky](./.husky) folder content to see what hooks are enabled. Lint-staged is used to guarantee
Expand Down
2 changes: 1 addition & 1 deletion apps/blog-app/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const nextConfig = {
},

// @ts-ignore
webpack: function (config, { defaultLoaders }) {
webpack: function (config, { _defaultLoaders }) {
config.module.rules.push({
test: /\.svg$/,
issuer: /\.(js|ts)x?$/,
Expand Down
1 change: 1 addition & 0 deletions apps/blog-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"eslint-plugin-prettier": "3.4.1",
"eslint-plugin-react": "7.24.0",
"eslint-plugin-react-hooks": "4.2.0",
"eslint-plugin-sonarjs": "0.10.0",
"eslint-plugin-testing-library": "4.12.0",
"jest": "27.1.0",
"jest-css-modules-transform": "4.3.0",
Expand Down
6 changes: 6 additions & 0 deletions apps/web-app/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
"@typescript-eslint/explicit-module-boundary-types": "off"
}
},
{
"files": ["src/backend/api/**/*.ts"],
"rules": {
"@typescript-eslint/explicit-module-boundary-types": "off"
}
},
{
"files": ["**/*.devtool.ts", "**/*.devtool.tsx"],
"rules": {
Expand Down
2 changes: 1 addition & 1 deletion apps/web-app/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const nextConfig = {
},

// @ts-ignore
webpack: (config, { defaultLoaders, isServer }) => {
webpack: (config, { isServer, _defaultLoaders }) => {
// A temp workaround for https://github.com/prisma/prisma/issues/6899#issuecomment-849126557
if (isServer) {
config.externals.push('_http_common');
Expand Down
1 change: 1 addition & 0 deletions apps/web-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"eslint-plugin-prettier": "3.4.1",
"eslint-plugin-react": "7.24.0",
"eslint-plugin-react-hooks": "4.2.0",
"eslint-plugin-sonarjs": "0.10.0",
"eslint-plugin-testing-library": "4.12.0",
"jest": "27.1.0",
"jest-css-modules-transform": "4.3.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/web-app/src/pages/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Props = {
};

export default function DemoRoute(
props: InferGetServerSidePropsType<typeof getServerSideProps>
_props: InferGetServerSidePropsType<typeof getServerSideProps>
) {
return <DemoPage />;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/web-app/src/pages/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Props = {
};

export default function HomeRoute(
props: InferGetServerSidePropsType<typeof getServerSideProps>
_props: InferGetServerSidePropsType<typeof getServerSideProps>
) {
return <HomePage />;
}
Expand Down
1 change: 1 addition & 0 deletions packages/core-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"eslint-plugin-prettier": "3.4.1",
"eslint-plugin-react": "7.24.0",
"eslint-plugin-react-hooks": "4.2.0",
"eslint-plugin-sonarjs": "0.10.0",
"eslint-plugin-testing-library": "4.12.0",
"jest": "27.1.0",
"microbundle": "0.13.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/core-lib/src/utils/random-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class RandomUtils {
* lower than max if max isn't an integer).
* @link https://stackoverflow.com/questions/1527803/generating-random-whole-numbers-in-javascript-in-a-specific-range/1527820#1527820
*/
static getRandomInt(min: number, max: number) {
static getRandomInt(min: number, max: number): number {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
Expand Down
11 changes: 9 additions & 2 deletions packages/db-main-prisma/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{
"root": true,
"extends": ["../../.eslintrc.base.json", "plugin:jsx-a11y/recommended"],
"extends": ["../../.eslintrc.base.json"],
"env": {
"browser": true
},
"overrides": []
"overrides": [
{
"files": ["*.seed.ts", "*.seed.js"],
"rules": {
"sonarjs/no-duplicate-string": "off"
}
}
]
}
1 change: 1 addition & 0 deletions packages/db-main-prisma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"eslint-plugin-jest": "24.4.0",
"eslint-plugin-jest-formatting": "3.0.0",
"eslint-plugin-prettier": "3.4.1",
"eslint-plugin-sonarjs": "0.10.0",
"jest": "27.1.0",
"keyword-extractor": "0.0.20",
"npm-run-all": "4.1.5",
Expand Down
1 change: 1 addition & 0 deletions packages/ui-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"eslint-plugin-prettier": "3.4.1",
"eslint-plugin-react": "7.24.0",
"eslint-plugin-react-hooks": "4.2.0",
"eslint-plugin-sonarjs": "0.10.0",
"eslint-plugin-testing-library": "4.12.0",
"jest": "27.1.0",
"microbundle": "0.13.3",
Expand Down
14 changes: 14 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3849,6 +3849,7 @@ __metadata:
eslint-plugin-prettier: 3.4.1
eslint-plugin-react: 7.24.0
eslint-plugin-react-hooks: 4.2.0
eslint-plugin-sonarjs: 0.10.0
eslint-plugin-testing-library: 4.12.0
jest: 27.1.0
microbundle: 0.13.3
Expand Down Expand Up @@ -3888,6 +3889,7 @@ __metadata:
eslint-plugin-jest: 24.4.0
eslint-plugin-jest-formatting: 3.0.0
eslint-plugin-prettier: 3.4.1
eslint-plugin-sonarjs: 0.10.0
jest: 27.1.0
keyword-extractor: 0.0.20
npm-run-all: 4.1.5
Expand Down Expand Up @@ -3924,6 +3926,7 @@ __metadata:
eslint-plugin-prettier: 3.4.1
eslint-plugin-react: 7.24.0
eslint-plugin-react-hooks: 4.2.0
eslint-plugin-sonarjs: 0.10.0
eslint-plugin-testing-library: 4.12.0
jest: 27.1.0
microbundle: 0.13.3
Expand Down Expand Up @@ -4916,6 +4919,7 @@ __metadata:
eslint-plugin-prettier: 3.4.1
eslint-plugin-react: 7.24.0
eslint-plugin-react-hooks: 4.2.0
eslint-plugin-sonarjs: 0.10.0
eslint-plugin-testing-library: 4.12.0
jest: 27.1.0
jest-css-modules-transform: 4.3.0
Expand Down Expand Up @@ -7479,6 +7483,15 @@ __metadata:
languageName: node
linkType: hard

"eslint-plugin-sonarjs@npm:0.10.0":
version: 0.10.0
resolution: "eslint-plugin-sonarjs@npm:0.10.0"
peerDependencies:
eslint: ^5.0.0 || ^6.0.0 || ^7.0.0
checksum: 6ef5b2050180a612b310610d9b1f2a89508ecf41326573cd62977ad085b25a6be7e31f47eee5857fb43b4bbd1bea1454419b52545ee3cb6cb2185a1938872009
languageName: node
linkType: hard

"eslint-plugin-testing-library@npm:4.12.0":
version: 4.12.0
resolution: "eslint-plugin-testing-library@npm:4.12.0"
Expand Down Expand Up @@ -17052,6 +17065,7 @@ resolve@^2.0.0-next.3:
eslint-plugin-prettier: 3.4.1
eslint-plugin-react: 7.24.0
eslint-plugin-react-hooks: 4.2.0
eslint-plugin-sonarjs: 0.10.0
eslint-plugin-testing-library: 4.12.0
graphql: 15.5.1
i18next: 20.4.0
Expand Down