Set up linters

This commit is contained in:
Nikita Karamov 2023-03-01 12:12:17 +01:00
parent 2b842ca027
commit 0a546bdf50
No known key found for this signature in database
GPG key ID: 41D6F71EE78E77CD
9 changed files with 938 additions and 29 deletions

2
.eslintignore Normal file
View file

@ -0,0 +1,2 @@
/dist/
/public/

23
.eslintrc.json Normal file
View file

@ -0,0 +1,23 @@
{
"env": {
"browser": true
},
"extends": ["eslint:recommended", "plugin:unicorn/recommended", "prettier"],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"overrides": [
{
"files": ["gulpfile.js", "api/*.js"],
"env": {
"node": true,
"browser": false
},
"rules": {
"unicorn/prefer-module": 0,
"unicorn/prefer-node-protocol": 0
}
}
]
}

View file

@ -1 +0,0 @@
14

27
.pre-commit-config.yaml Normal file
View file

@ -0,0 +1,27 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: mixed-line-ending
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: check-json
- id: check-toml
- id: check-yaml
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v2.7.1"
hooks:
- id: prettier
additional_dependencies:
- prettier@2
- repo: https://github.com/pre-commit/mirrors-eslint
rev: "v8.35.0"
hooks:
- id: eslint
additional_dependencies:
- eslint
- eslint-config-prettier
- eslint-plugin-unicorn
- prettier

View file

@ -1,3 +1,5 @@
*.md
/public
/.vercel
/dist/
/public/
/.vercel/
pnpm-lock.yaml

View file

@ -1 +1,4 @@
{}
{
"quoteProps": "consistent",
"trailingComma": "es5"
}

View file

@ -1,20 +1,22 @@
const { join, resolve } = require("path");
const path = require("path");
const gulp = require("gulp");
const postcss = require("gulp-postcss");
const sass = require("gulp-sass")(require("sass"));
const sourcemaps = require("gulp-sourcemaps");
const terser = require("gulp-terser");
const SOURCE_DIR = resolve(__dirname, "src");
const OUTPUT_DIR = resolve(__dirname, "public");
const SOURCE_DIR = path.resolve(__dirname, "src");
const OUTPUT_DIR = path.resolve(__dirname, "public");
function html() {
return gulp.src(join(SOURCE_DIR, "index.html")).pipe(gulp.dest(OUTPUT_DIR));
return gulp
.src(path.join(SOURCE_DIR, "index.html"))
.pipe(gulp.dest(OUTPUT_DIR));
}
function css() {
return gulp
.src(join(SOURCE_DIR, "scss", "*.scss"))
.src(path.join(SOURCE_DIR, "scss", "*.scss"))
.pipe(sourcemaps.init())
.pipe(sass.sync().on("error", sass.logError))
.pipe(postcss([require("autoprefixer"), require("postcss-csso")]))
@ -24,24 +26,24 @@ function css() {
function js() {
return gulp
.src([join(SOURCE_DIR, "main.js"), join(SOURCE_DIR, "count.js")])
.src([path.join(SOURCE_DIR, "main.js"), path.join(SOURCE_DIR, "count.js")])
.pipe(sourcemaps.init())
.pipe(terser({ ecma: 5 }))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(OUTPUT_DIR));
}
function static() {
function staticFiles() {
return gulp
.src(join(SOURCE_DIR, "static", "**", "*"))
.src(path.join(SOURCE_DIR, "static", "**", "*"))
.pipe(gulp.dest(OUTPUT_DIR));
}
exports.default = gulp.parallel(html, css, js, static);
exports.default = gulp.parallel(html, css, js, staticFiles);
exports.watch = () => {
gulp.watch(join(SOURCE_DIR, "index.html"), html);
gulp.watch(join(SOURCE_DIR, "scss", "*.scss"), css);
gulp.watch(join(SOURCE_DIR, "*.js"), js);
gulp.watch(join(SOURCE_DIR, "static", "**", "*"), static);
gulp.watch(path.join(SOURCE_DIR, "index.html"), html);
gulp.watch(path.join(SOURCE_DIR, "scss", "*.scss"), css);
gulp.watch(path.join(SOURCE_DIR, "*.js"), js);
gulp.watch(path.join(SOURCE_DIR, "static", "**", "*"), staticFiles);
};

View file

@ -13,11 +13,17 @@
"scripts": {
"build": "gulp",
"dev": "gulp watch",
"fmt": "prettier --write .",
"lint": "prettier --check . && eslint .",
"test": "pnpm run lint",
"serve": "sirv ./public --dev"
},
"devDependencies": {
"autoprefixer": "^10.4.2",
"browserslist": "^4.19.1",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-unicorn": "^45.0.2",
"gulp": "^4.0.2",
"gulp-postcss": "^9.0.1",
"gulp-sass": "^5.1.0",
@ -25,7 +31,7 @@
"gulp-terser": "^2.1.0",
"postcss": "^8.4.6",
"postcss-csso": "^6.0.0",
"prettier": "2.5.1",
"prettier": "^2.8.4",
"sass": "^1.49.7",
"sirv-cli": "^2.0.2"
}

File diff suppressed because it is too large Load diff