-
Notifications
You must be signed in to change notification settings - Fork 115
FECSRules
为了更准确的匹配到百度的前端代码规范,有部分规则是定制,或者修改官方的规则。
基于 Nodeca Team 的插件,当时 eslint 还没有 indent 的实现。目前功能除了与官方一致外(配置参数有区别),还针对数组拼接 HTML 时的缩进作了处理。
在官方 valid-jsdoc
基本上增强:
- 文档注释前面要有一个空行;
- 检查 @file 和 @author;
- 针对 RestElement 参数的注释类型检查;
- 内置类型的大小写严格检查;
- 不同的错误信息有不同的标识,便于 reporter 归类到不同的错误;
- 所有错误信息包含具体的行列位置,包含异常(来自 doctrine2,对 doctrine 的 hack)。
在官方的基础上,针对 AMD 模块的 factory 作豁免。
在配置冒号前不允许空格情况下,识别并允许基于冒号对齐情况。
增加一个配置项 disallowMultiBlankLine
,用于设置是否允许文件末尾连续空白行的情况。
在官方 camelcase
项目上的增强:
- 允许标识符前后的
--
(比如 __dirname); - 允许通过
quote
配置项对Property
类型的标识符作豁免; - 允许配置
ignore
数组来作豁免,支持前后使用/
标识为正则的匹配; - 允许使用文档注释的
@private
对单个下划线前缀的方法作豁免。
以上三个规则全部基于官方的基础上,是作了更准备的报错位置调整,见 issue 46。
根据百度前端代码规则实现:
[强制] 对象创建时,如果一个对象的所有
属性
均可以不添加引号,则所有属性
不得添加引号。 [强制] 对象创建时,如果任何一个属性
需要添加引号,则所有属性
必须添加'
。
在官方规则的增加了 window.eval
的使用检查。
[建议] 尽量避免使用
eval
函数。
[强制] 遍历数组不使用
for in
。
[强制] 模块定义中只允许使用
local require
,不允许使用global require
。
[强制] 模块
id
必须符合标准。
根据 jsx 的特点,对 jsx 中出现的标签名或属性将作用域中的同名变量标记为已使用。
// Learn TypeScript: // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import AssetMgr from './framework/AssetMgr'; import AudioMgr from './framework/AudioMgr'; import EventMgr from './framework/EventMgr'; import ObjectPoolMgr from './framework/ObjectPoolMgr'; import TimerMgr from './framework/TimerMgr'; import UIMgr from './framework/UIMgr'; import Instance from './framework/utils/Instance'; import PropMgr from './logic/common/PropMgr'; import UserInfo from './logic/common/UserInfo'; import ArtDataMgr from './logic/data/ArtDataMgr'; import ConfigArtGroupMgr from './logic/data/ConfigArtGroupMgr'; import ConfigArtMgr from './logic/data/ConfigArtMgr'; import ConfigMgr from './logic/data/ConfigMgr'; import SaveDataMgr from './logic/data/SaveDataMgr'; import HttpLogicMgr from './logic/net/HttpLogicMgr'; import GridMgr from './logic/painting/GridMgr'; import PaintingGridDataMgr from './logic/painting/PaintingGridDataMgr'; import PaintingPaletteDataMgr from './logic/painting/PaintingPaletteDataMgr'; import StarBlinkEffectMgr from './logic/ui/effects/StarBlinkEffectMgr';
const { ccclass, property } = cc._decorator;
@ccclass export default class App extends cc.Component { static UIRoot: cc.Node = null; static timerMgr: TimerMgr = null; static eventMgr: EventMgr = null; static assetMgr: AssetMgr = null; static uiMgr: UIMgr = null; static poolMgr: ObjectPoolMgr = null; static httpMgr: HttpLogicMgr = null; static audioMgr: AudioMgr = null; static userInfo: UserInfo = null; static gridMgr: GridMgr = null; static paintingPaletteDataMgr: PaintingPaletteDataMgr = null; static saveDataMgr: SaveDataMgr = null; static paintingGridDataMgr: PaintingGridDataMgr = new PaintingGridDataMgr(); static propMgr: PropMgr = null; static artDataMgr: ArtDataMgr = null; private static configMgr: ConfigMgr = null; static configArtMgr: ConfigArtMgr = null; static configArtGroupMgr: ConfigArtGroupMgr = null;; /** * 测试网络开关 / static isOpenNetwork: boolean = true; /* * 是否是链接本地 / static isLocalNetwork: boolean = true; /* * 是否开启网络log */ static isOpenNetworkLog: boolean = true;
async onLoad() {
App.UIRoot = cc.find('Canvas/UIRoot');
// cc.debug.setDisplayStats(false);
// cc.game.setFrameRate(30)
// 注册单例
App.eventMgr = Instance.get(EventMgr);
App.timerMgr = Instance.get(TimerMgr);
App.assetMgr = Instance.get(AssetMgr);
App.poolMgr = Instance.get(ObjectPoolMgr);
App.httpMgr = Instance.get(HttpLogicMgr);
App.audioMgr = Instance.get(AudioMgr);
App.userInfo = Instance.get(UserInfo);
App.paintingGridDataMgr = Instance.get(PaintingGridDataMgr);
App.paintingPaletteDataMgr = Instance.get(PaintingPaletteDataMgr);
App.propMgr = Instance.get(PropMgr);
App.saveDataMgr = Instance.get(SaveDataMgr);
App.artDataMgr = Instance.get(ArtDataMgr);
App.gridMgr = Instance.get(GridMgr);
/** ----初始化数据库 */
const dbOk = await App.saveDataMgr.init(UserInfo.PaintingDataKey);// 增加新的数据表需要同时修改版本号
console.log('dbOk = ' + dbOk);
// App.userInfo.clearAllDatas()
/** ----加载数据 */
App.userInfo.loadData();
/** ----初始化ui管理 */
// 注册事件监听
App.eventMgr.registerOwner(UIMgr);
// 初始化ui管理类
App.uiMgr = Instance.get(UIMgr).init(App.UIRoot);
/** ----加载art数据 编辑器生成的 */
await App.artDataMgr.loadData();
await this.cacheViews(['PaintingView']);
/** ----初始化configs */
App.configMgr = Instance.get(ConfigMgr);
await App.configMgr.loadConfig('dataConfigs');
App.configArtGroupMgr = Instance.get(ConfigArtGroupMgr).init(App.configMgr.getTable('artGroup'));
App.configArtMgr = Instance.get(ConfigArtMgr).init(App.configMgr.getTable('art'));
/** ----初始化tile缓存 */
let prefab = await App.assetMgr.load('prefabs/TiledTile', cc.Prefab);
App.poolMgr.createObjectPool('TiledTile', (prefab as cc.Prefab), 110 * 110 * 4);
prefab = await App.assetMgr.loadPrefab('prefabs/StarArrayEffect');
App.poolMgr.createObjectPool('StarArrayEffect', (prefab as cc.Prefab), 110 * 110 * 4);
prefab = await App.assetMgr.loadPrefab('prefabs/StarBlinkEffect');
App.poolMgr.createObjectPool('StarBlinkEffect', (prefab as cc.Prefab), 300);
/** ----进入游戏 */
App.uiMgr.showView('HomeBottomView', 0);
cc.game.setFrameRate(30);
}
private async cacheViews(names: string[]) {
for (let index = 0; index < names.length; index++) {
const name = names[index];
const Prefab = await App.assetMgr.load(`ui/${name}`, cc.Prefab);
App.poolMgr.createObjectPool(name, (Prefab as cc.Prefab), 1);
}
}
update(dt) {
App.timerMgr.update(dt);
}
/**
* 显示绘制界面
* @param data
*/
static async GotoPainting(data: any) {
App.userInfo.paintingRecord(data.id);
App.userInfo.saveData();
await App.uiMgr.showView('PaintingView', data);
App.uiMgr.hideView('HomeBottomView');
App.uiMgr.hideView('CutImageView');
// cc.game.setFrameRate(60);
}
/**
* 回到主界面
*/
static async GotoHome() {
if (!App.uiMgr.isViewShow('HomeBottomView')) {
await App.uiMgr.showView('HomeBottomView');
}
}
}