Commit 0b7874c6 authored by Thisara Kavinda's avatar Thisara Kavinda

feat: integrate eslint & prettier

parent 1660b520
// to ignore lint rules on js files
*.js
*.css
\ No newline at end of file
{
"env": {
"browser": true,
"es2021": true,
"jest": true
},
"extends": [
"plugin:react/recommended",
"standard-with-typescript",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"project": ["**/tsconfig.json"]
},
"plugins": ["react", "react-hooks", "prettier"],
"rules": {
"no-debugger": "error",
"react/jsx-uses-react": "off",
"react/react-in-jsx-scope": "off",
"import/export": "warn",
"react-hooks/rules-of-hooks": "warn",
"@typescript-eslint/triple-slash-reference": "off",
"@typescript-eslint/consistent-type-definitions": "off",
"@typescript-eslint/strict-boolean-expressions": "off",
"@typescript-eslint/prefer-nullish-coalescing": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/promise-function-async": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/array-type": "off",
"prettier/prettier": "warn",
"no-console": "warn",
"@typescript-eslint/no-confusing-void-expression": "off",
"@typescript-eslint/consistent-indexed-object-style": "warn",
"@typescript-eslint/await-thenable": "off",
"@typescript-eslint/consistent-type-imports": "warn",
"no-restricted-imports": ["warn", { "patterns": ["../*"] }]
},
"settings": {
"react": {
"version": "detect"
}
}
}
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
echo "\n Checking format, lint and types in your project before committing"
# Check Prettier standards
npm run format ||
(
echo "\n Prettier Check Failed.\n Run npm run format, add changes and try commit again.\n";
false;
)
# Check ESLint Standards
npm run lint-staged ||
(
echo "\n ESLint Check Failed. \n Make the required changes listed above, add changes and try to commit again.\n"
false;
)
# If everything passes... Now we can commit
echo "Build is completed... I am committing this now. \n"
.cache
package-lock.json
public
node_modules
yarn.lock
\ No newline at end of file
{
"semi": false,
"tabWidth": 2,
"printWidth": 100,
"singleQuote": true,
"trailingComma": "all",
"jsxSingleQuote": true,
"bracketSpacing": true
}
\ No newline at end of file
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.formatOnPaste": false
}
\ No newline at end of file
...@@ -3,24 +3,29 @@ ...@@ -3,24 +3,29 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@testing-library/jest-dom": "^5.17.0", "@testing-library/jest-dom": "^6.4.1",
"@testing-library/react": "^13.4.0", "@testing-library/react": "^14.2.1",
"@testing-library/user-event": "^13.5.0", "@testing-library/user-event": "^14.5.2",
"@types/jest": "^27.5.2", "@types/jest": "^29.5.12",
"@types/node": "^16.18.79", "@types/node": "^20.11.16",
"@types/react": "^18.2.52", "@types/react": "^18.2.52",
"@types/react-dom": "^18.2.18", "@types/react-dom": "^18.2.18",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-scripts": "5.0.1", "react-scripts": "5.0.1",
"typescript": "^4.9.5", "typescript": "5.1.6",
"web-vitals": "^2.1.4" "web-vitals": "^3.5.2"
}, },
"scripts": { "scripts": {
"start": "react-scripts start", "start": "react-scripts start",
"build": "react-scripts build", "build": "react-scripts build",
"test": "react-scripts test", "test": "react-scripts test",
"eject": "react-scripts eject" "eject": "react-scripts eject",
"format": "prettier --write src/**/*.{ts,tsx,css} --config ./.prettierrc.json",
"lint": "eslint src --ext ts --ext tsx --ext js",
"lint:fix": "eslint --fix src --ext ts --ext tsx --ext js",
"lint-staged": "lint-staged",
"prepare": "husky install"
}, },
"eslintConfig": { "eslintConfig": {
"extends": [ "extends": [
...@@ -43,5 +48,29 @@ ...@@ -43,5 +48,29 @@
"main": "index.js", "main": "index.js",
"repository": "http://gitlab.sliit.lk/thisaraAtSliit/speakezy_frontend.git", "repository": "http://gitlab.sliit.lk/thisaraAtSliit/speakezy_frontend.git",
"author": "Thisara Kavinda <thisara48kavinda@gmail.com>", "author": "Thisara Kavinda <thisara48kavinda@gmail.com>",
"license": "MIT" "license": "MIT",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^9.1.0",
"eslint-config-standard-with-typescript": "^43.0.1",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-n": "^15.0.0 || ^16.0.0 ",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-react": "^7.33.2",
"husky": "^8.0.0",
"lint-staged": "^15.2.1",
"prettier": "3.2.5"
},
"lint-staged": {
"src/**/*.{js,jsx,ts,tsx,css}": [
"yarn format",
"yarn lint:fix"
]
},
"simple-git-hooks": {
"pre-commit": "yarn lint-staged"
}
} }
import React from 'react'; import React from 'react'
import { render, screen } from '@testing-library/react'; import { render, screen } from '@testing-library/react'
import App from './App'; import App from './App'
test('renders learn react link', () => { test('renders learn react link', () => {
render(<App />); render(<App />)
const linkElement = screen.getByText(/learn react/i); const linkElement = screen.getByText(/learn react/i)
expect(linkElement).toBeInTheDocument(); expect(linkElement).toBeInTheDocument()
}); })
import React from 'react'; import React from 'react'
import logo from './logo.svg'; import logo from './logo.svg'
import './App.css'; import './App.css'
function App() { function App() {
return ( return (
<div className="App"> <div className='App'>
<header className="App-header"> <header className='App-header'>
<img src={logo} className="App-logo" alt="logo" /> <img src={logo} className='App-logo' alt='logo' />
<p> <p>
Edit <code>src/App.tsx</code> and save to reload. Edit <code>src/App.tsx</code> and save to reload.
</p> </p>
<a <a
className="App-link" className='App-link'
href="https://reactjs.org" href='https://reactjs.org'
target="_blank" target='_blank'
rel="noopener noreferrer" rel='noopener noreferrer'
> >
Learn React Learn React
</a> </a>
</header> </header>
</div> </div>
); )
} }
export default App; export default App
body { body {
margin: 0; margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
sans-serif;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
} }
code { code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace;
monospace;
} }
import React from 'react'; import React from 'react'
import ReactDOM from 'react-dom/client'; import ReactDOM from 'react-dom/client'
import './index.css'; import './index.css'
import App from './App'; import App from './App'
import reportWebVitals from './reportWebVitals'; import reportWebVitals from './reportWebVitals'
const root = ReactDOM.createRoot( const root = ReactDOM.createRoot(document.getElementById('root') ?? document.body)
document.getElementById('root') as HTMLElement
);
root.render( root.render(
<React.StrictMode> <React.StrictMode>
<App /> <App />
</React.StrictMode> </React.StrictMode>,
); )
// If you want to start measuring performance in your app, pass a function // If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log)) // to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals(); reportWebVitals()
import { ReportHandler } from 'web-vitals'; import { type ReportHandler } from 'web-vitals'
const reportWebVitals = (onPerfEntry?: ReportHandler) => { const reportWebVitals = (onPerfEntry?: ReportHandler) => {
if (onPerfEntry && onPerfEntry instanceof Function) { if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { void import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry); getCLS(onPerfEntry)
getFID(onPerfEntry); getFID(onPerfEntry)
getFCP(onPerfEntry); getFCP(onPerfEntry)
getLCP(onPerfEntry); getLCP(onPerfEntry)
getTTFB(onPerfEntry); getTTFB(onPerfEntry)
}); })
} }
}; }
export default reportWebVitals; export default reportWebVitals
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
// allows you to do things like: // allows you to do things like:
// expect(element).toHaveTextContent(/react/i) // expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom // learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom'; import '@testing-library/jest-dom'
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment