Skip to content

Commit

Permalink
chore: add perfectionist eslint plugin wd-147
Browse files Browse the repository at this point in the history
  • Loading branch information
what1s1ove committed Nov 14, 2023
1 parent c1b2c75 commit 0f83e3e
Show file tree
Hide file tree
Showing 29 changed files with 476 additions and 294 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extends:
- plugin:import/recommended
- plugin:sonarjs/recommended
- plugin:unicorn/recommended
- plugin:perfectionist/recommended-natural

plugins:
- simple-import-sort
Expand Down Expand Up @@ -92,6 +93,9 @@ rules:
- error
simple-import-sort/exports:
- error
perfectionist/sort-named-imports:
- error
- type: alphabetical
import/exports-last:
- error
import/group-exports:
Expand Down
2 changes: 1 addition & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { ProjectPrefix } from './project.config.js'

/** @type {import('@commitlint/types').UserConfig} */
let configuration = {
extends: [`@commitlint/config-conventional`],
parserPreset: {
parserOpts: {
issuePrefixes: ProjectPrefix.APPS.map((it) => `${it}-`),
},
},
extends: [`@commitlint/config-conventional`],
rules: {
'references-empty': [2, `never`],
},
Expand Down
44 changes: 22 additions & 22 deletions eleventy.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let esbuild = require(`esbuild`)
let lightningcss = require(`lightningcss`)
let htmlMin = require(`html-minifier-terser`)
let { existsSync } = require(`fs`)
let { readFile, writeFile, mkdir } = require(`fs/promises`)
let { mkdir, readFile, writeFile } = require(`fs/promises`)
let browserslist = require(`browserslist`)
let packageJson = require(`./package.json`)
let Image = require(`@11ty/eleventy-img`)
Expand All @@ -13,19 +13,19 @@ let fs = require(`node:fs/promises`)
let isDevelopment = process.env.NODE_ENV === `development`

let Path = {
CSS: `./source/styles/index.css`,
JS: {
MAIN: `./source/scripts/index.js`,
FORM: `./source/scripts/form.js`,
},
DB: `./source/database.json`,
COPY: [
`./source/fonts`,
`./source/files`,
`./source/sounds`,
`./source/manifest.webmanifest`,
`./source/favicon.ico`,
],
CSS: `./source/styles/index.css`,
DB: `./source/database.json`,
JS: {
FORM: `./source/scripts/form.js`,
MAIN: `./source/scripts/index.js`,
},
}

/** @param {import("@11ty/eleventy").UserConfig} config */
Expand All @@ -44,7 +44,6 @@ let init = (config) => {
config.addTemplateFormats(`json`)

config.addExtension(`json`, {
outputFileExtension: `json`,
compile: async (_content, url) => {
if (url !== Path.DB) {
return
Expand All @@ -65,6 +64,7 @@ let init = (config) => {
}),
)
},
outputFileExtension: `json`,
})

// html
Expand All @@ -84,7 +84,6 @@ let init = (config) => {
config.addTemplateFormats(`css`)

config.addExtension(`css`, {
outputFileExtension: `css`,
compile: async (_content, url) => {
if (url !== Path.CSS) {
return
Expand All @@ -108,13 +107,13 @@ let init = (config) => {
: code
}
},
outputFileExtension: `css`,
})

// js
config.addTemplateFormats(`js`)

config.addExtension(`js`, {
outputFileExtension: `js`,
compile: async (_content, url) => {
if (url !== Path.JS.MAIN) {
return
Expand All @@ -124,12 +123,12 @@ let init = (config) => {
let {
outputFiles: [formOutputFile],
} = await esbuild.build({
bundle: true,
entryPoints: [Path.JS.FORM],
target: `es2020`,
minify: true,
bundle: true,
write: false,
sourcemap: isDevelopment,
target: `es2020`,
write: false,
})

let isFolderExists = existsSync(`build/scripts`)
Expand All @@ -145,24 +144,24 @@ let init = (config) => {
let {
outputFiles: [mainOutputFile],
} = await esbuild.build({
bundle: true,
entryPoints: [url],
target: `es2020`,
minify: true,
bundle: true,
write: false,
sourcemap: isDevelopment,
target: `es2020`,
write: false,
})

return mainOutputFile.text
}
},
outputFileExtension: `js`,
})

// png
config.addTemplateFormats(`png`)

config.addExtension(`png`, {
outputFileExtension: `png`,
compile: async (_content, url) => {
return async () => {
let {
Expand All @@ -174,27 +173,27 @@ let init = (config) => {

if (url.includes(`.photo.`)) {
await Image(url, {
formats: [`webp`, `avif`],
outputDir: `build/images`,
filenameFormat: (_id, source, _width, format) => {
let extension = path.extname(source)
let name = path.basename(source, extension)

return `${name}.${format}`
},
formats: [`webp`, `avif`],
outputDir: `build/images`,
})
}

return originalImg.buffer
}
},
outputFileExtension: `png`,
})

// svg
config.addTemplateFormats(`svg`)

config.addExtension(`svg`, {
outputFileExtension: `svg`,
compile: (content, url) => {
return () => {
if (url === `./source/images/icons/icon.svg`) {
Expand All @@ -204,16 +203,17 @@ let init = (config) => {
return svgo.optimize(content).data
}
},
outputFileExtension: `svg`,
})

return {
dataTemplateEngine: `njk`,
dir: {
input: `source`,
output: `build`,
},
dataTemplateEngine: `njk`,
markdownTemplateEngine: `njk`,
htmlTemplateEngine: `njk`,
markdownTemplateEngine: `njk`,
passthroughFileCopy: true,
templateFormats: [`md`, `njk`],
}
Expand Down
Loading

0 comments on commit 0f83e3e

Please sign in to comment.