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

feat: eslint + Typescript config #3

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": ["@babel/preset-env", ["@babel/preset-react", { "runtime": "automatic" }]]
"presets": ["@babel/preset-env", ["@babel/preset-react", { "runtime": "automatic" }], "@babel/preset-typescript"]
}
84 changes: 84 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"airbnb",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"plugin:react/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": ["react", "react-hooks", "@typescript-eslint", "prettier", "unused-imports"],
"rules": {
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-use-before-define": "off",
"import/no-extraneous-dependencies": "off",
"camelcase": "off",
"consistent-return": "off",
"no-param-reassign": "off",
"no-use-before-define": "off",
"prettier/prettier": "error",
"react-hooks/exhaustive-deps": "warn",
"react-hooks/rules-of-hooks": "error",
"react/jsx-props-no-spreading": "off",
"react/require-default-props": "off",
"react/react-in-jsx-scope": "off",
"unused-imports/no-unused-imports": "error",
"react/jsx-uses-react": "off",
"react/function-component-definition": [
"error",
{
"namedComponents": ["function-declaration", "arrow-function"],
"unnamedComponents": "arrow-function"
}
],
"unused-imports/no-unused-vars": [
"warn",
{ "vars": "all", "varsIgnorePattern": "^_", "args": "after-used", "argsIgnorePattern": "^_" }
],
"jsx-a11y/label-has-associated-control": [
"error",
{
"required": {
"some": ["nesting", "id", "name"]
}
}
],
"react/jsx-filename-extension": [
1,
{
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
],
"import/prefer-default-export": "off",
"import/extensions": [
"error",
"ignorePackages",
{
"ts": "never",
"tsx": "never",
"js": "never",
"jsx": "never"
}
]
},
"settings": {
"import/resolver": {
"typescript": {
"paths": "./tsconfig.json"
},
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
}
}
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,26 @@ jobs:
# with:
# flags: unittests
# fail_ci_if_error: true
react_lint:
name: Node.js linter
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04]
node-version: [18]

steps:
- uses: actions/checkout@v3
- name: Setting up Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install yarn
run: npm install --global yarn

- name: Install Node.js 18 dependencies
run: yarn install

- name: Run Node.js lint
run: yarn lint
19 changes: 18 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"scripts": {
"start": "webpack serve --mode=development --open",
"build": "webpack --mode=production",
"dev": "webpack --mode=production --watch"
"dev": "webpack --mode=production --watch",
"lint": "eslint react-app --ext .js,.ts,.jsx,.tsx",
"lint-fix": "eslint react-app --ext .js,.ts,.jsx,.tsx --fix"
},
"dependencies": {
"@babel/core": "^7.22.10",
Expand All @@ -28,6 +30,21 @@
"webpack-merge": "^5.9.0"
},
"devDependencies": {
"@babel/preset-typescript": "^7.22.15",
"@types/react": "^18.2.21",
"@types/react-dom": "^18.2.7",
"@typescript-eslint/eslint-plugin": "^6.5.0",
"@typescript-eslint/parser": "^6.5.0",
"eslint": "^8.38.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.8.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-unused-imports": "^2.0.0",
"prettier": "^3.0.3",
"typescript": "^5.2.2",
"webpack-dev-server": "^4.15.1"
Expand Down
13 changes: 13 additions & 0 deletions react-app/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import './App.css';
import BasicComponent from './BasicComponent';

const App = () => {
return (
<div className="container">
<h1 className="title">Images Gallery XBlock</h1>
<BasicComponent title="John" />
</div>
);
};

export default App;
25 changes: 25 additions & 0 deletions react-app/BasicComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// All this code will be removed, it's for testing TypeScript
import { FC } from 'react';
import { UserI } from './interfaces';

interface Props {
title: string;
}

const userData: UserI = {
name: 'test',
age: 40,
isActive: true,
logs: []
};

const BasicComponent: FC<Props> = ({ title }) => {
console.log(userData);
return (
<div>
<h1>Name: {title}</h1>
</div>
);
};

export default BasicComponent;
1 change: 1 addition & 0 deletions react-app/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
import React from 'react';
import ReactDOM from 'react-dom/client';

Expand Down
13 changes: 13 additions & 0 deletions react-app/interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// All this code will be removed, it's for testing TypeScript
interface Log {
id: string;
date: Date;
message: string;
}

export interface UserI {
name: string;
age: number;
isActive: boolean;
logs: Log[];
}
33 changes: 33 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": true,
"types": ["node"],
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": false,
"noEmit": true,
"jsx": "react-jsx",
"baseUrl": "./",
"paths": {
"@/*": ["react-app"]
}
},
"include": ["react-app"],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 12,
"sourceType": "module",
"tsconfigRootDir": "./"
}
}
Loading