mirror of
https://gitee.com/layui/layui.git
synced 2025-11-24 08:33:12 +08:00
* style: 统一代码格式,修复ESLint错误 - 为所有模块添加尾随逗号 - 修复缺少分号的语句 - 统一对象字面量格式 - 添加ESLint配置文件和文档 - 更新package.json中的脚本和依赖项 * build: 添加 ESLint 配置文件以支持 IE9+ 兼容性 * refactor(upload): 使用已缓存的hint实例替换直接调用 优化代码性能,避免重复实例化hint对象,直接使用模块顶部已缓存的实例 * chore: 更新.gitignore文件以包含更多忽略规则 添加了更多常见的临时文件、编辑器文件、构建输出目录和运行时数据的忽略规则,使项目更加整洁并避免不必要的文件被提交到版本控制中 * fix(lay.js): 修复passive事件监听器选项的返回值 确保getter函数返回true以正确支持passive事件监听 * refactor(form): 移除表单模块中的冗余代码 删除表单模块中无实际作用的冗余代码行,这些代码只是将属性重新赋值为自身,没有实际功能意义 * fix(form): 修复复选框状态处理逻辑 确保复选框的 indeterminate 和 checked 状态被正确转换为布尔值,并优化事件调用时的空格格式 * feat(eslint): 完善 ESLint 配置并添加 VSCode 支持 添加 VSCode 配置文件以支持 ESLint 自动修复和格式化 更新 ESLint 配置,增强代码风格和兼容性规则 修复 package.json 中的脚本拼写错误并添加 format 脚本 调整 .gitignore 以允许特定 VSCode 配置文件 * style: 统一代码中的引号格式并修复缩进问题 统一将双引号改为单引号,修复部分代码缩进不一致的问题,提升代码风格一致性 * docs: 删除过时的ESLint配置文档文件 * build: 采用 prettier 作为代码格式化工具,剔除 ESLint 格式化部分 * chore: 剔除 .vscode/ 配置,保持编辑器中立 * build: 修改 ESLint 为「扁平化配置」方式,避免大量参数堆砌 * chore: 格式化代码 * ci: 添加 git hooks 和 CI 环节把关代码风格 * ci: update * ci: update * test: 测试 ci format * ci: 改用 husky 作为 git hooks,与 Layui 3 保持一致 经测试,simple-git-hooks 生成的 pre-commit 默认为 sh,在 Windows 不兼容(必须用 git bash 执行 commits) * build: 新增 CI 和生产环境跳过 husky 安装的判断 * build: 剔除重复配置 * build: 优化 eslint 配置 --------- Co-authored-by: 贤心 <3277200+sentsim@users.noreply.github.com>
106 lines
3.4 KiB
JavaScript
106 lines
3.4 KiB
JavaScript
import js from '@eslint/js';
|
||
import globals from 'globals';
|
||
import { defineConfig, globalIgnores } from 'eslint/config';
|
||
import eslintConfigPrettier from 'eslint-config-prettier/flat';
|
||
|
||
// Layui 全局变量定义
|
||
globals.layui = {
|
||
layui: false,
|
||
lay: false,
|
||
// jQuery
|
||
$: false,
|
||
jQuery: false,
|
||
// 国际化 API
|
||
Intl: false,
|
||
// 模块系统支持
|
||
exports: false, // CommonJS 导出对象
|
||
module: false, // CommonJS 模块对象
|
||
require: false, // CommonJS 导入函数
|
||
define: false // AMD/RequireJS 模块定义函数
|
||
};
|
||
|
||
export default defineConfig([
|
||
// 全局忽略规则
|
||
globalIgnores([
|
||
'**/dist/',
|
||
'.temp/**', // 临时文件目录 - 临时生成的文件
|
||
'docs/**', // 文档目录 - 文档相关文件,无需代码检查
|
||
'src/modules/jquery.js' // 第三方库文件 - jQuery 源码,无需检查
|
||
]),
|
||
|
||
// Browser 环境 - 兼容 IE9+
|
||
{
|
||
files: ['src/**/*.js'],
|
||
plugins: { js },
|
||
extends: ['js/recommended'],
|
||
languageOptions: {
|
||
ecmaVersion: 5, // IE9+ 支持 ES5 语法,确保代码兼容性
|
||
sourceType: 'script', // 非模块类型,即使用 <script> 标签直接引入
|
||
globals: { ...globals.browser, ...globals.layui }
|
||
},
|
||
rules: {
|
||
// 仅允许 console.warn 和 console.error
|
||
'no-console': ['error', { allow: ['warn', 'error'] }],
|
||
|
||
// 未使用变量:警告未使用的变量,但忽略函数参数和局部变量
|
||
// 某些变量可能用于向后兼容或特定场景
|
||
'no-unused-vars': [
|
||
'warn',
|
||
{
|
||
args: 'none',
|
||
caughtErrors: 'none', // 忽略以 catch 捕获的错误变量
|
||
vars: 'local'
|
||
}
|
||
],
|
||
|
||
// 重复声明:警告重复声明的变量,但不强制报错(兼容旧代码)
|
||
'no-redeclare': 'warn',
|
||
|
||
// 无用转义:警告不必要的转义字符,但不强制报错(避免误报)
|
||
'no-useless-escape': 'warn',
|
||
|
||
// 空代码块:警告空的代码块,可能是未完成的代码
|
||
'no-empty': 'warn',
|
||
|
||
/**
|
||
* ES6+ 特性规则 - IE9+ 兼容性考虑
|
||
* 下规则全部关闭
|
||
*/
|
||
|
||
'prefer-const': 'off', // 不强制使用 const(IE9 不支持)
|
||
'no-var': 'off', // 允许使用 var(IE9 主要变量声明方式)
|
||
'prefer-arrow-callback': 'off', // 不强制使用箭头函数(IE9 不支持)
|
||
'prefer-template': 'off', // 不强制使用模板字符串(IE9 不支持)
|
||
'object-shorthand': 'off', // 不强制使用对象简写(IE9 不支持)
|
||
'prefer-destructuring': 'off', // 不强制使用解构赋值(IE9 不支持)
|
||
'prefer-rest-params': 'off', // 不强制使用剩余参数(IE9 不支持)
|
||
'prefer-spread': 'off', // 不强制使用扩展运算符(IE9 不支持)
|
||
|
||
/**
|
||
* 函数相关规则
|
||
*/
|
||
|
||
// 函数风格:不限制函数声明风格,允许函数声明和函数表达式混用
|
||
'func-style': 'off',
|
||
|
||
// 内部声明:允许在代码块内部声明函数(兼容旧代码模式)
|
||
'no-inner-declarations': 'off'
|
||
}
|
||
},
|
||
|
||
// Node.js 环境 - 构建脚本
|
||
{
|
||
files: ['*.{js,cjs}'],
|
||
plugins: { js },
|
||
extends: ['js/recommended'],
|
||
languageOptions: {
|
||
ecmaVersion: 'latest',
|
||
sourceType: 'commonjs', // 使用 CommonJS 模块系统
|
||
globals: { ...globals.node }
|
||
},
|
||
rules: {}
|
||
},
|
||
|
||
eslintConfigPrettier // 避免 Prettier 和 ESLint 规则冲突
|
||
]);
|