Skip to content

Commit

Permalink
add config file for nestjs
Browse files Browse the repository at this point in the history
  • Loading branch information
vc-lbmadesia committed Dec 20, 2023
1 parent fe87ac2 commit 32737b6
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 7 deletions.
1 change: 1 addition & 0 deletions config/common/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.next
.cache
package-lock.json
dist
public
node_modules
next-env.d.ts
Expand Down
2 changes: 2 additions & 0 deletions config/common/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"yzhang.markdown-all-in-one",
"christian-kohler.path-intellisense",
"esbenp.prettier-vscode",
"chakrounanas.turbo-console-log",
"sonarsource.sonarlint-vscode"

]
}
82 changes: 82 additions & 0 deletions config/nestjs/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
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",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: [".eslintrc.js"],
rules: {
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/explicit-function-return-type": "error",
"@typescript-eslint/explicit-module-boundary-types": "warn",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/no-invalid-this": "off",
"@typescript-eslint/no-unused-expressions": "warn",
"@typescript-eslint/return-await": "warn",
"@typescript-eslint/member-ordering": "off",
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/prefer-optional-chain": "error",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/naming-convention": [
"error",
{ selector: "default", format: ["strictCamelCase"] },
{
selector: "variable",
format: ["strictCamelCase", "UPPER_CASE", "PascalCase"],
},
{
selector: "parameter",
modifiers: ["unused"],
format: ["strictCamelCase"],
leadingUnderscore: "allow",
},
{ selector: "property", format: null },
{ selector: "typeProperty", format: null },
{ selector: "typeLike", format: ["StrictPascalCase"] },
{ selector: "enumMember", format: ["UPPER_CASE"] },
],
"no-useless-return": "error",
"no-constant-condition": "warn",
"max-len": [
"error",
{
code: 200,
skipBlankLines: true,
skipComments: true,
},
],
"max-lines": [
"error",
{
max: 1000,
},
],
"no-multiple-empty-lines": [
"error",
{
max: 2,
maxEOF: 1,
},
],
"no-console": "error",
"no-mixed-operators": "error",
"keyword-spacing": "error",
"multiline-ternary": ["error", "never"],
"no-undef": "error",
"no-whitespace-before-property": "error",
"nonblock-statement-body-position": "error",
},
};
9 changes: 9 additions & 0 deletions config/nestjs/.lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"{src,apps,libs,test}/**/*.ts": [
"eslint --fix",
"prettier --config ./prettierrc --write"
],
"{src,apps,libs,test}/**/*.json": [
"prettier --config ./.prettierrc --write"
]
}
8 changes: 8 additions & 0 deletions config/nestjs/prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"singleQuote": true,
"semi": true,
"tabWidth": 2,
"trailingComma": "all",
"printWidth": 80,
"endOfLine": "auto"
}
File renamed without changes.
File renamed without changes.
46 changes: 39 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ function help(code) {
}

const reactPackagesInstallCmd = ({ install, devInstall, forceCMD }) => {
console.log("Installing required plugins...");
execSync(
`${install} @types/node @types/react @types/react-dom eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-config-next eslint-config-prettier eslint-plugin-jsx-a11y eslint-plugin-prettier eslint-plugin-promise eslint-plugin-react eslint-plugin-react-hooks husky lint-staged prettier ${devInstall} ${forceCMD}`,
{
Expand All @@ -24,17 +23,54 @@ const reactPackagesInstallCmd = ({ install, devInstall, forceCMD }) => {
);
};

const nestPackagesInstallCmd = ({ install, devInstall, forceCMD }) => {
execSync(
`${install} eslint-config-prettier eslint-plugin-prettier eslint-plugin-promise husky lint-staged prettier ${devInstall} ${forceCMD}`,
{
stdio: "inherit",
}
);
};

const reactEslintConfigCmd = () => {
const configPath = resolve(__dirname, `./config/nextjs/.eslintrc.json`);
const configPathForPrettier = resolve(
__dirname,
`./config/nextjs/.prettierrc.json`
);
const configPathForLintStage = resolve(
__dirname,
`./config/nestjs/.lintstagedrc.json`
);

copyFileSync(configPath, ".eslintrc.json");
copyFileSync(configPathForPrettier, ".prettierrc.json");
copyFileSync(configPathForLintStage, ".lintstagedrc.json");
};

const nestEslintConfigCmd = () => {
const configPathForLint = resolve(__dirname, `./config/nestjs/.eslintrc.js`);
const configPathForPrettier = resolve(
__dirname,
`./config/nestjs/.prettierrc`
);
const configPathForLintStage = resolve(
__dirname,
`./config/nestjs/.lintstagedrc.json`
);
copyFileSync(configPathForLint, ".eslintrc.js");
copyFileSync(configPathForPrettier, ".prettierrc");
copyFileSync(configPathForLintStage, ".lintstagedrc.json");
};

const packagesInstallCmds = {
nextjs: reactPackagesInstallCmd,
nestjs: nestPackagesInstallCmd,
};

const eslintConfigCmds = {
nextjs: reactEslintConfigCmd,
nestjs: nestEslintConfigCmd,
};

async function init() {
Expand Down Expand Up @@ -100,6 +136,7 @@ async function init() {

const installRequiredPackages = packagesInstallCmds[technology];

console.log("Installing required plugins...");
installRequiredPackages({ install, uninstall, devInstall });

execSync(`npm pkg set scripts.lint="next lint --fix`, {
Expand All @@ -122,12 +159,7 @@ async function init() {
stdio: "inherit",
});

const configNames = [
".gitattributes",
".lintstagedrc.json",
".prettierignore",
".prettierrc.json",
];
const configNames = [".gitattributes", ".prettierignore"];

console.log("Coping configuration files");
const eslintConfigCmd = eslintConfigCmds[technology];
Expand Down

0 comments on commit 32737b6

Please sign in to comment.