Skip to content

Commit

Permalink
Add configurations for linting scripts and add global ignores (#5843)
Browse files Browse the repository at this point in the history
* Add configurations for linting scripts and add global ignores

* optimize eslint ignore patterns

* remove `node_modules` since it's already ignored by default

* implement code suggestions

Co-Authored-By: PikachuEXE <[email protected]>

---------

Co-authored-by: PikachuEXE <[email protected]>
  • Loading branch information
ChunkyProgrammer and PikachuEXE authored Oct 10, 2024
1 parent b9214a0 commit 64d73f4
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 15 deletions.
2 changes: 2 additions & 0 deletions _scripts/ProcessLocalesPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class ProcessLocalesPlugin {
}

for (let [locale, data] of this.locales) {
// eslint-disable-next-line no-async-promise-executor
promises.push(new Promise(async (resolve) => {
if (IS_DEV_SERVER && compiler.fileTimestamps) {
const filePath = join(this.inputDir, `${locale}.yaml`)
Expand Down Expand Up @@ -131,6 +132,7 @@ class ProcessLocalesPlugin {
})

compiler.hooks.afterCompile.tap(PLUGIN_NAME, (compilation) => {
// eslint-disable-next-line no-extra-boolean-cast
if (!!compiler.watching) {
// watch locale files for changes
compilation.fileDependencies.addAll(this.filePaths)
Expand Down
2 changes: 1 addition & 1 deletion _scripts/getShakaLocales.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { readFileSync, readdirSync } = require('fs')
function getPreloadedLocales() {
const localesFile = readFileSync(`${__dirname}/../node_modules/shaka-player/dist/locales.js`, 'utf-8')

const localesLine = localesFile.match(/^\/\/ LOCALES: ([\w, -]+)$/m)
const localesLine = localesFile.match(/^\/\/ LOCALES: ([\w ,-]+)$/m)

if (!localesLine) {
throw new Error("Failed to parse shaka-player's preloaded locales")
Expand Down
4 changes: 2 additions & 2 deletions _scripts/patchShaka.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function removeRobotoFont() {
let cssContents = readFileSync(cssFileHandle, 'utf-8')

const beforeReplacement = cssContents.length
cssContents = cssContents.replace(/@font-face\{font-family:Roboto;[^}]+\}/, '')
cssContents = cssContents.replace(/@font-face{font-family:Roboto;[^}]+}/, '')

if (cssContents.length !== beforeReplacement) {
ftruncateSync(cssFileHandle)
Expand Down Expand Up @@ -100,7 +100,7 @@ async function replaceAndDownloadMaterialIconsFont() {
let newFontCSS = text.match(/(@font-face\s*{[^}]+})/)[1].replaceAll('\n', '')


const urlMatch = newFontCSS.match(/https:\/\/fonts\.gstatic\.com\/s\/materialiconsround\/(?<version>[^\/]+)\/[^.]+\.(?<extension>[\w]+)/)
const urlMatch = newFontCSS.match(/https:\/\/fonts\.gstatic\.com\/s\/materialiconsround\/(?<version>[^/]+)\/[^.]+\.(?<extension>\w+)/)

const url = urlMatch[0]
const { version, extension } = urlMatch.groups
Expand Down
59 changes: 49 additions & 10 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ const compat = new FlatCompat({
})

export default [
{
ignores: [
'dist/',
'eslint.config.mjs'
]
},
...fixupConfigRules(
compat.config({
extends: ['standard']
Expand All @@ -37,9 +43,7 @@ export default [
'**/*.{js,vue}',
],
ignores: [
'**/node_modules',
'**/_scripts',
'**/dist',
'_scripts/',
],
plugins: {
unicorn: eslintPluginUnicorn,
Expand Down Expand Up @@ -125,9 +129,7 @@ export default [
{
files: ['**/*.json'],
ignores: [
'**/node_modules/**',
'**/_scripts/**',
'**/dist/**',
'_scripts/',
],

languageOptions: {
Expand All @@ -152,10 +154,8 @@ export default [
{
files: ['**/*.{yml,yaml}'],
ignores: [
'**/node_modules/**',
'**/_scripts/**',
'**/dist/**',
'**/.github/**',
'.github/',
'_scripts/'
],

languageOptions: {
Expand Down Expand Up @@ -192,4 +192,43 @@ export default [
},
},
},
{
files: ['_scripts/*.js'],
languageOptions: {
globals: {
...globals.node
},
ecmaVersion: 'latest',
},

plugins: {
unicorn: eslintPluginUnicorn,
},

rules: {
'no-console': 'off',
'n/no-path-concat': 'off',
'unicorn/better-regex': 'error',
}
},
{
files: ['_scripts/*.mjs'],
languageOptions: {
globals: {
...globals.node,
},
ecmaVersion: 'latest',
sourceType: 'module',
},

plugins: {
unicorn: eslintPluginUnicorn,
},

rules: {
'no-console': 'off',
'n/no-path-concat': 'off',
'unicorn/better-regex': 'error',
}
}
]
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"lint-all": "run-p lint lint-json",
"lint": "run-p eslint-lint lint-style",
"lint-fix": "run-p eslint-lint-fix lint-style-fix",
"eslint-lint": "eslint --config eslint.config.mjs \"./src/**/*.js\" \"./src/**/*.vue\" \"./static/**/*.js\"",
"eslint-lint-fix": "eslint --config eslint.config.mjs --fix \"./src/**/*.js\" \"./src/**/*.vue\" \"./static/**/*.js\"",
"eslint-lint": "eslint --config eslint.config.mjs \"./src/**/*.js\" \"./src/**/*.vue\" \"./static/**/*.js\" \"./_scripts/*.js\" \"./_scripts/*.mjs\"",
"eslint-lint-fix": "eslint --config eslint.config.mjs --fix \"./src/**/*.js\" \"./src/**/*.vue\" \"./static/**/*.js\" \"./_scripts/*.js\" \"./_scripts/*.mjs\"",
"lint-json": "eslint --config eslint.config.mjs \"./static/**/*.json\"",
"lint-style": "stylelint \"**/*.{css,scss}\"",
"lint-style-fix": "stylelint --fix \"**/*.{css,scss}\"",
Expand Down

0 comments on commit 64d73f4

Please sign in to comment.