Skip to content
Open
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
7 changes: 7 additions & 0 deletions node-style-guide/tekdi-style-guides/node-style-guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Node.js Styling Tools

### Introduction:
This configuration file integrates ESLint and Prettier to enforce coding standards and ensure consistent code formatting within our project. It leverages various ESLint plugins and rules to maintain code quality and readability.

Setting up ESLint with Prettier in your Node.js project helps maintain code quality and consistent code formatting standards across your codebase.
ESLint checks for code errors, enforces coding style rules, and supports JavaScript and TypeScript-specific configurations, while Prettier automatically formats code to ensure consistent styling such as indentation, line breaks, and quote styles.
76 changes: 76 additions & 0 deletions node-style-guide/tools/node/eslintrc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
## ESLint
ESLint is a powerful tool for identifying and fixing problems in JavaScript and TypeScript code. It helps maintain code quality by enforcing consistent coding standards and best practices. By analyzing your code for potential errors and stylistic issues, ESLint ensures that your codebase remains clean, readable, and maintainable.

## Add the following scripts to your package.json file:

```json
"scripts": {
"lint:fix": "eslint src --ext .js,.ts,.tsx --fix",
"lint-and-format": "npm run lint:fix && npm run format"
}
```

## Configure your project with eslint
create or update the .eslintrc file in your project root directory:
``` js
module.exports = {
root: true, // Indicates this is the root configuration file
ignorePatterns: ["projects/**/*"], // Ignore specific patterns
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
},
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
'plugin:prettier/recommended',
],
plugins: ['@typescript-eslint', 'prettier'],
rules: {
'prettier/prettier': 'error',
'emi': ['error', 'always'], // require semicolons at the end of statements
'camelcase': ['error', { properties: 'never' }], // enforce camelCase variable names
'func-names': ['error', 'as-needed'], // require function names to be descriptive
'quotes': ['error', 'single'], // prefer single quotes over double quotes
'no-unused-vars': 'error', // disallow unused variables
'no-duplicate-imports': 'error', // disallow duplicate imports
'no-unused-imports': 'error', // disallow unused imports
'no-void-elements': 'error', // disallow void elements
'pace-before-blocks': ['error', 'always'], // enforce consistent spacing before blocks
'pace-before-function-paren': ['error', 'always'], // enforce consistent spacing before function parentheses
'indent-legacy': ['error', 2, { SwitchCase: 1 }], // enforce consistent indentation for switch cases
'linebreak-style': ['error', 'unix'], // enforce consistent line breaks (UNIX-style)
'@typescript-eslint/no-unused-vars': 'error', // disallow unused variables in TypeScript
'no-empty-catch': 'error', // disallow empty catch clauses
'no-unnecessary-finally': 'error', // disallow unnecessary finally blocks
'no-unused-private-class-members': 'error', // disallow unused private class members
'array-bracket-spacing': ['error', 'never'], // enforce consistent array brackets
'func-call-spacing': ['error', 'never'], // enforce consistent function call parentheses
'@typescript-eslint/no-unused-type-parameters': 'error', // disallow unused type parameters
'arrow-parens': ['error', 'always'], // enforce consistent arrow function parentheses
'comma-style': ['error', 'last'] // enforce consistent comma style
},
env: {
node: true,
es6: true,
},
};
```

## Here are the main points for the provided ESLint configuration with explanations:

root: true: This setting indicates that this is the root ESLint configuration file, and ESLint should not look for other configuration files in parent directories. This is useful in monorepo setups or projects with multiple ESLint configurations.
Ignoring Patterns:

ignorePatterns: ["projects/**/*"]: This setting specifies that all files and directories under the projects directory should be ignored by ESLint. This is useful for excluding certain parts of the codebase from being linted.

env: This setting specifies the environments in which the code is expected to run, such as node: true (Node.js environment) and es6: true (enabling ES6 globals and syntax). This ensures that ESLint correctly recognizes the environment-specific globals and syntax.
24 changes: 24 additions & 0 deletions node-style-guide/tools/node/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Installation
Execute the following command

This npm command installs ESLint and Prettier along with essential plugins and configurations for TypeScript projects. ESLint ensures code quality and adherence to coding standards, while Prettier enforces consistent code formatting. Together with TypeScript-specific extensions, these tools streamline development by promoting clean, standardized code.

```
npm install --save-dev eslint prettier eslint-config-prettier eslint-plugin-prettier @typescript-eslint/parser @typescript-eslint/eslint-plugin
```

eslint: The core ESLint library.

prettier: A popular code formatter.

eslint-config-prettier: Disables ESLint rules that conflict with Prettier.

eslint-plugin-prettier: Runs Prettier as an ESLint rule.

@typescript-eslint/parser and @typescript-eslint/eslint-plugin: ESLint parser and plugin for TypeScript support.

## Command to lint and format the code:
```
npm run lint-and-format
```

28 changes: 28 additions & 0 deletions node-style-guide/tools/node/prettierrc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Prettier
Prettier is an opinionated code formatter that enforces consistent code style by parsing your code and re-printing it with its own rules. It supports multiple languages and integrates seamlessly with various editors and build tools. By automating code formatting, Prettier reduces the time spent on manual styling and helps teams adhere to a unified code style across their projects.


## Scripts

Add the following scripts to your package.json
```json
"scripts": {
"format": "prettier --write src",
}
```

## Configure your project with prettier

```js
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": true,
"arrowParens": "avoid",
"endOfLine": "lf"
}
```