Skip to content

Commit

Permalink
chore: improve eslint config & fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
techfg committed Dec 27, 2024
1 parent a2a9c01 commit d885718
Show file tree
Hide file tree
Showing 37 changed files with 209 additions and 176 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gh-pages-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
push:
branches: main
# Allows you to run this workflow manually from the Actions tab on GitHub.
# eslint-disable-next-line yml/no-empty-mapping-value
# eslint-disable-next-line yml/no-empty-mapping-value -- does not accept any value
workflow_dispatch:

# Allow this job to clone the repo and create a page deployment
Expand Down
File renamed without changes.
218 changes: 114 additions & 104 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,141 +1,151 @@
import html from 'eslint-plugin-html';
import globals from 'globals';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { FlatCompat } from '@eslint/eslintrc';
import mdxeslint from 'eslint-plugin-mdx';
import jseslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import eslintPluginAstro from 'eslint-plugin-astro';
import eslintConfigPrettier from 'eslint-config-prettier';
import pluginJs from '@eslint/js';
import pluginTypeScript from 'typescript-eslint';
import eslintPluginYml from 'eslint-plugin-yml';
import eslintPluginAstro from 'eslint-plugin-astro';
import eslintPluginJsonc from 'eslint-plugin-jsonc';
import eslintPluginHtmlInlineScripts from 'eslint-plugin-html';
import eslintConfigPrettier from 'eslint-config-prettier';
import eslintPluginHtml from '@html-eslint/eslint-plugin';
import eslintPluginHtmlParser from '@html-eslint/parser';
import eslintPluginMdx from 'eslint-plugin-mdx';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { FlatCompat } from '@eslint/eslintrc';

// TODO: Change to import.meta.dirname once Node 18 is no longer supported (Node >= >=20.11.0)
const __dirname = dirname(fileURLToPath(import.meta.url));

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname
});

/** @type {import('eslint').Linter.Config[]} */
export default [
{
files: [
'**/*.js',
'**/*.jsx',
'**/*.cjs',
'**/*.mjs',
'**/*.html',
'**/*.yml',
'**/*.yaml',
'**/*.md',
'**/*.mdx',
'**/*.json',
'**/*.jsonc',
'**/*.ts',
'**/*.tsx',
'**/*.astro'
]
},
...[
...compat.extends('jquery'),
{
languageOptions: {
sourceType: 'script',
ecmaVersion: 5,
globals: { ...globals.browser, ...globals.jquery }
},
rules: {
'one-var': ['error', { var: 'consecutive' }],
strict: ['error', 'function'],
'no-nested-ternary': 0,
camelcase: 0,
'no-console': ['error', { allow: ['warn', 'error'] }]
}
}
].map((cfg) => ({
ignores: [
'site/**',
'!site/src/components/demos/**/map.{js,html}',
'**/*.{mjs,cjs}'
],
...cfg
})),
{
ignores: [
'tests/redist/',
'examples/redist/',
'**/build/',
'**/dist/',
'**/node_modules/',
'!.github',
'!.vscode',
'**/package-lock.json',
'!**/.*.json',
'!**/.*.jsonc',
'docs/',
'**/*.d.ts',
'**/.astro/'
'**/redist/**',
'**/build/**',
'**/dist/**',
'**/.astro/**',
'docs/**'
]
},
jseslint.configs.recommended,
...compat.extends('jquery'),
eslintConfigPrettier,
...eslintPluginYml.configs['flat/standard'],
...eslintPluginYml.configs['flat/prettier'],
...eslintPluginJsonc.configs['flat/recommended-with-jsonc'],
...eslintPluginAstro.configs.recommended,
{
plugins: {
html
},
linterOptions: {
reportUnusedDisableDirectives: true
},
files: ['site/src/components/demos/**/map.js'],
languageOptions: {
globals: {
...globals.browser,
...globals.jquery
},
ecmaVersion: 5,
sourceType: 'script'
},
settings: {
'html/indent': '+2',
'html/report-bad-indent': 'error'
},
rules: {
'one-var': ['error', { var: 'consecutive' }],
strict: ['error', 'function'],
'no-nested-ternary': 0,
camelcase: 0,
'no-console': ['error', { allow: ['warn', 'error'] }]
parserOptions: {
ecmaFeatures: {
// these files are directly displayed in `Scripts` tab in website so avoid having to include use strict
impliedStrict: true
}
}
}
},
{
...mdxeslint.flat,
processor: mdxeslint.createRemarkProcessor({
files: ['.remarkrc.cjs'],
languageOptions: { globals: { ...globals.node } }
},
pluginJs.configs.recommended,
...pluginTypeScript.config({
files: ['site/**/*.{js,mjs,cjs,ts}'],
ignores: ['site/src/components/demos/**/map.js'],
extends: [
pluginTypeScript.configs.strictTypeChecked,
pluginTypeScript.configs.stylisticTypeChecked
],
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: `${__dirname}/site`
}
}
}),
...eslintPluginAstro.configs.recommended,
{
...eslintPluginMdx.flat,
processor: eslintPluginMdx.createRemarkProcessor({
lintCodeBlocks: true
}),
rules: {
...mdxeslint.flat.rules,
...eslintPluginMdx.flat.rules,
'no-unused-vars': 'off'
}
},
mdxeslint.flatCodeBlocks,
{
files: ['**/*.mjs'],
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
...eslintPluginMdx.flatCodeBlocks,
rules: {
...eslintPluginMdx.flatCodeBlocks.rules,
'no-var': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-require-imports': 'off'
}
},
{
files: ['.remarkrc.js'],
// Configuration for `<script>` tag using TypeScript in `.astro` files and code blocks in markdown.
files: ['site/**/*.astro/*.ts', 'site/**/*.{md,mdx}/*.js'],
languageOptions: {
globals: {
...globals.node
parserOptions: {
project: false
}
},
rules: {
...pluginTypeScript.configs.disableTypeChecked.rules
}
},
...eslintPluginYml.configs['flat/recommended'],
...eslintPluginJsonc.configs['flat/recommended-with-jsonc'],
{
files: ['site/**/*'],
...eslintPluginHtml.configs['flat/recommended'],
files: ['**/*.html'],
plugins: {
eslintPluginHtmlInlineScripts,
'@html-eslint': eslintPluginHtml
},
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
parser: eslintPluginHtmlParser
},
settings: {
'html/indent': '+2',
'html/report-bad-indent': 'error'
},
rules: {
...eslintPluginHtml.configs['flat/recommended'].rules,
'@html-eslint/require-img-alt': 'off',
/* Disable rules that conflict with prettier */
'@html-eslint/require-closing-tags': 'off',
'@html-eslint/no-multiple-empty-lines': 'off',
'@html-eslint/no-extra-spacing-attrs': 'off',
'@html-eslint/element-newline': 'off',
'@html-eslint/indent': 'off',
'@html-eslint/quotes': 'off',
'@html-eslint/no-trailing-spaces': 'off',
'@html-eslint/attrs-newline': 'off'
}
},
...tseslint.config({
files: ['site/**/*.ts'],
extends: [tseslint.configs.recommended],
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: `${__dirname}/site`
}
}
}),
{
files: ['site/astro.config.mjs'],
languageOptions: {
globals: {
...globals.node
}
}
}
eslintConfigPrettier
];
2 changes: 1 addition & 1 deletion examples/altimages.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>AltImages Demo</title>
Expand Down
4 changes: 2 additions & 2 deletions examples/autoresize.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Automatic Resize Demo</title>
Expand Down Expand Up @@ -183,7 +183,7 @@ <h2>Automatic Resize Demo</h2>
style="width: 100%"
/>
</div>
<div style="clear: both" />
<div style="clear: both"></div>
</div>
<div style="border: 5px solid orange; padding: 20px; margin: 40px">
<img
Expand Down
22 changes: 1 addition & 21 deletions examples/boundlist.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Bound List Test</title>
Expand Down Expand Up @@ -69,26 +69,6 @@
);
}

// eslint-disable-next-line no-unused-vars
function getBoundListForAreas(areas) {
var listItems = $.map(areas, function (area) {
var $a = $(area),
key = $a.data('name'),
description = $a.data('description');

return buildListItem(key, description);
});
return $veglist.empty().append(listItems).find('input');
}

// eslint-disable-next-line no-unused-vars
function getBoundListFromItems(items) {
var listItems = $.map(items, function (item) {
return buildListItem(item.key, item.value);
});
return $veglist.empty().append(listItems).find('input');
}

var $image = $('#veg_image'),
$veglist = $('#veg_list'),
imageOptions = {
Expand Down
2 changes: 1 addition & 1 deletion examples/frog.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Frog Menu Demo</title>
Expand Down
2 changes: 1 addition & 1 deletion examples/includekeys.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>IncludeKeys Test</title>
Expand Down
2 changes: 1 addition & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>ImageMapster Examples</title>
Expand Down
2 changes: 1 addition & 1 deletion examples/manualresize.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Manual Resize Demo</title>
Expand Down
2 changes: 1 addition & 1 deletion examples/multiple-maps.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Multiple Maps Demo</title>
Expand Down
2 changes: 1 addition & 1 deletion examples/navigate-full-frame.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Navigation Demo - Full Frame</title>
Expand Down
2 changes: 1 addition & 1 deletion examples/navigate-full.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Navigation Demo - Full</title>
Expand Down
2 changes: 1 addition & 1 deletion examples/navigate-simple.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Navigation Demo - Simple</title>
Expand Down
2 changes: 1 addition & 1 deletion examples/navigate-target.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Navigation Target Demo</title>
Expand Down
2 changes: 1 addition & 1 deletion examples/nohref.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Nohref & Href Attribute Values Test</title>
Expand Down
2 changes: 1 addition & 1 deletion examples/rebind.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Rebind Test</title>
Expand Down
Loading

0 comments on commit d885718

Please sign in to comment.