-
Notifications
You must be signed in to change notification settings - Fork 52
Add linting and formatting #79
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
Merged
jamesrweb
merged 28 commits into
P5-wrapper:master
from
yevdyko:style/add-linting-and-formatting
Apr 9, 2021
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
b38f085
Add prettier
yevdyko 11d4276
Add prettier config
yevdyko 3b45c3f
Format component using prettier
yevdyko 05e9530
Add lint-staged
yevdyko 0fb5e3e
Add lint-staged config
yevdyko 70ac63a
Add simple-git-hooks
yevdyko c3367ae
Add pre-commit git hook
yevdyko 5bd812f
Add eslint packages for typescript
yevdyko 3af1794
Add eslint config
yevdyko cb3eaad
Add react specific linting rules for eslint
yevdyko 7c1ee09
Update eslint config with react plugin preset
yevdyko 1b6612f
Add packages to integrate eslint with prettier rules
yevdyko 63ec2bb
Update eslint config with recommended prettier setup
yevdyko 9a58a4c
Avoid using trailing commas
yevdyko 9770c31
Add ci github action workflow
yevdyko eb793a8
Add documentation about eslint configuration
yevdyko d44e2e1
Add documentation about prettier configuration
yevdyko ca06551
Format the whole project using prettier
yevdyko 41e3178
Actualize ignored files
yevdyko 0866ab0
Remove unused styles
yevdyko 5d9fe39
Extend eslint config to use with js files
yevdyko e807316
Fix linting for example js files
yevdyko 7626241
Update ci.yml
jamesrweb c0960a9
Update package.json
jamesrweb c554824
Update package-lock.json file after removing packages
yevdyko 70d13e2
Move testing to the separate job in CI
yevdyko 04048fd
Format JSON files as well
yevdyko dcc6067
Format README file using Prettier
yevdyko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| { | ||
| "presets": ["@babel/preset-env", "@babel/preset-react"] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| dist | ||
| node_modules | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| { | ||
yevdyko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "root": true, | ||
| "env": { | ||
| "browser": true | ||
| }, | ||
| "parserOptions": { | ||
| "ecmaVersion": 2018, | ||
| "sourceType": "module" | ||
| }, | ||
| "settings": { | ||
| "react": { | ||
| "version": "detect" | ||
| } | ||
| }, | ||
| "extends": [ | ||
| "eslint:recommended", | ||
| "plugin:react/recommended", | ||
| "plugin:prettier/recommended" | ||
| ], | ||
| "overrides": [ | ||
| { | ||
| "files": ["*.ts", "*.tsx"], | ||
| "parser": "@typescript-eslint/parser", | ||
| "plugins": ["@typescript-eslint"], | ||
| "extends": [ | ||
| "eslint:recommended", | ||
| "plugin:react/recommended", | ||
| "plugin:@typescript-eslint/recommended", | ||
| "plugin:prettier/recommended" | ||
| ], | ||
| "rules": { | ||
| "@typescript-eslint/ban-ts-comment": "off", | ||
| "@typescript-eslint/explicit-module-boundary-types": "off" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| name: CI workflow | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ master ] | ||
| pull_request: | ||
| branches: [ master ] | ||
|
|
||
| jobs: | ||
| lint: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Check out the repository | ||
| uses: actions/checkout@v2 | ||
| with: | ||
| ref: ${{ github.head_ref }} | ||
|
|
||
| - name: Setup node | ||
| uses: actions/setup-node@v2 | ||
| with: | ||
| node-version: 14.x | ||
|
|
||
| - name: Cache npm packages | ||
| uses: actions/cache@v2 | ||
| id: npm-cache | ||
| with: | ||
| path: ~/.npm | ||
| key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-npm- | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
| env: | ||
| CI: true | ||
|
|
||
| - name: Format files | ||
| run: npm run format | ||
|
|
||
| - name: Commit formatting changes | ||
| uses: stefanzweifel/git-auto-commit-action@v4 | ||
| with: | ||
| commit_message: Apply formatting changes | ||
| branch: ${{ github.head_ref }} | ||
yevdyko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - name: Lint files | ||
| run: npm run lint | ||
|
|
||
| - name: Linting failed (attempting fix...) | ||
| if: ${{ failure() }} | ||
| run: npm run lint:fix | ||
|
|
||
| - name: Commit fixed lint issues | ||
| uses: stefanzweifel/git-auto-commit-action@v4 | ||
| with: | ||
| commit_message: Apply fixed lint issues | ||
| branch: ${{ github.head_ref }} | ||
|
|
||
| test: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Check out the repository | ||
| uses: actions/checkout@v2 | ||
| with: | ||
| ref: ${{ github.head_ref }} | ||
|
|
||
| - name: Setup node | ||
| uses: actions/setup-node@v2 | ||
| with: | ||
| node-version: 14.x | ||
|
|
||
| - name: Cache npm packages | ||
| uses: actions/cache@v2 | ||
| id: npm-cache | ||
| with: | ||
| path: ~/.npm | ||
| key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-npm- | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
| env: | ||
| CI: true | ||
|
|
||
| - name: Run test suite | ||
| run: npm run test | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| dist | ||
| node_modules | ||
| package.json | ||
| package-lock.json | ||
| *.html | ||
jamesrweb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
yevdyko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "trailingComma": "none" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| # ESLint | ||
|
|
||
| ESLint is a static code analysis tool for identifying problematic patterns found in JavaScript code, including Typescript. | ||
|
|
||
| ## Packages | ||
|
|
||
| We use the following packages: | ||
|
|
||
| - `eslint`: This is the core ESLint library. | ||
| - `eslint-plugin-react`: This contains some standard linting rules for React code. | ||
| - `@typescript-eslint/parser`: This allows TypeScript code to be linted. | ||
| - `@typescript-eslint/eslint-plugin`: This contains some standard linting rules for TypeScript code. | ||
| - `eslint-config-prettier`: This turns off all rules that are unnecessary or might conflict with Prettier. | ||
| - `eslint-plugin-prettier`: This runs Prettier as an ESLint rule and reports differences as individual ESLint issues. | ||
|
|
||
| ## Configuration | ||
|
|
||
| ESLint is configured in a `.eslintrc` file in the project root. | ||
|
|
||
| The configuration file contains the basic settings for JS files used in the examples: | ||
|
|
||
| 1. Specify an environment provide browser global variables. | ||
|
|
||
| ```json | ||
| { | ||
| "env": { | ||
| "browser": true | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| 2. Parser options are set to use ECMAScript 2018 syntax and ECMAScript modules. | ||
|
|
||
| ```json | ||
| { | ||
| "parserOptions": { | ||
| "ecmaVersion": 2018, | ||
| "sourceType": "module" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| 3. Automatically select the React version you have installed. | ||
|
|
||
| ```json | ||
| { | ||
| "settings": { | ||
| "react": { | ||
| "version": "detect" | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| 4. Presets that extend the given ESLint configuration: | ||
|
|
||
| - `eslint:recommended`: This is the core eslint recommended rules. | ||
| - `plugin:react/recommended`: This plugin exports a recommended configuration that enforces React good practices. | ||
| - `plugin:prettier/recommended`: This plugin disables all formatting-related ESLint rules, and only enables rules that detect potential bugs. Must be added as the last extension. | ||
|
|
||
| We override the following properties for the Typescript related files: | ||
|
|
||
| 1. A parser that allows ESLint to understand TypeScript syntax. | ||
|
|
||
| ```json | ||
| { | ||
| "parser": "@typescript-eslint/parser" | ||
| } | ||
| ``` | ||
|
|
||
| 2. Register the installed plugin package for linting TypeScript. | ||
|
|
||
| ```json | ||
| { | ||
| "plugins": ["@typescript-eslint"] | ||
| } | ||
| ``` | ||
|
|
||
| 3. Presets that extend the given ESLint configuration: | ||
|
|
||
| - `plugin:@typescript-eslint/recommended`: This plugin exports all the recommended rules for TypeScript. | ||
|
|
||
| ## Usage | ||
|
|
||
| Run the following script to validate the code: | ||
|
|
||
| ``` | ||
| npm run lint | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Prettier | ||
|
|
||
| Prettier is a code formatter that enforces a consistent style by parsing the code and re-printing it with its own rules. | ||
|
|
||
| ## Configuration | ||
|
|
||
| There are just a few options that can be configured in Prettier. They can found in a `.prettierrc` file in the project root. | ||
|
|
||
| The configuration file contains the following: | ||
|
|
||
| - `"trailingComma": "none"`: Print without trailing commas. | ||
|
|
||
| See more details in the [documentation](https://prettier.io/docs/en/options.html). | ||
|
|
||
| ## Usage | ||
|
|
||
| Run the following script to format the files with `js`, `jsx`, `ts`, `tsx` and `md` extensions: | ||
|
|
||
| ``` | ||
| npm run format | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.