Skip to content

Commit

Permalink
replace JSHint and JSCS with ESLint [DONE]
Browse files Browse the repository at this point in the history
  • Loading branch information
Minwe committed Apr 20, 2016
1 parent b3a4b86 commit 8b54dc6
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 114 deletions.
78 changes: 67 additions & 11 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,62 @@
"node": true
},
"rules": {
"no-bitwise": 2,
"camelcase": 2,
// Strict Mode
// @see http://eslint.org/docs/rules/strict
"strict": [
2,
"safe"
],

// Variables
// @see http://eslint.org/docs/rules/#variables
"no-undef": 2,
"no-unused-vars": 2,

// Possible Errors
// @see http://eslint.org/docs/rules/#possible-errors
"comma-dangle": [2, "never"],
"no-empty": [2, {"allowEmptyCatch": true}],

// Best Practices
// @see http://eslint.org/docs/rules/#best-practices
"curly": 2,
"no-unused-expressions": 2,
"dot-notation": 2,
"no-caller": 2,
"no-multi-str": 2,
"no-unused-expressions": [2, {
"allowShortCircuit": true,
"allowTernary": true
}],
"no-with": 2,
"wrap-iife": [
2,
"any"
],

// Stylistic Issues
// @see http://eslint.org/docs/rules/#stylistic-issues
"array-bracket-spacing": [2, "never"],
"camelcase": [2, {
"properties": "always"
}],
"comma-style": [2, "last"],
"eol-last": 2,
"keyword-spacing": [
2,
{
"before": true,
"after": true,
"overrides": {}}
],
"indent": [
2,
2,
{
"SwitchCase": 1
}
],
"linebreak-style": [2, "unix"],
"max-len": [
2,
80,
Expand All @@ -28,16 +69,31 @@
}
],
"new-cap": 2,
"no-caller": 2,
"no-bitwise": 2,
"no-mixed-spaces-and-tabs": 2,
"no-trailing-spaces": [2, {"skipBlankLines": true }],
"one-var": [2, "never"],
"quotes": [
2,
"single"
"single",
{"avoidEscape": true, "allowTemplateLiterals": true}
],
"no-undef": 2,
"no-unused-vars": 2,
"strict": [
2,
"safe"
]
"quote-props": [2, "as-needed"],
"semi": ["error", "always"],
"spaced-comment": ["error", "always"],
"space-before-function-paren": [2, {
"anonymous": "never",
"named": "never"
}],
"space-in-parens": [2, "never"],
"space-infix-ops": [2, {"int32Hint": true}],
"space-unary-ops": [
2, {
// `words` applies to unary word operators,
// such as: new, delete, typeof, void, yield
"words": true,
// nonwords - applies to unary operators such as: -, +, --, ++, !, !!
"nonwords": false
}]
}
}
95 changes: 0 additions & 95 deletions .jscsrc

This file was deleted.

6 changes: 4 additions & 2 deletions docs/styleguide/javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ next: widget.html

## 代码质量控制工具

Amaze UI 使用 [JSHint](http://jshint.com/)[JSCS](https://github.com/jscs-dev/node-jscs) 控制代码质量。
Amaze UI 使用 ~~[JSHint](http://jshint.com/)[JSCS](https://github.com/jscs-dev/node-jscs)~~[ESLint](http://eslint.org/)控制代码质量。

详细设置参见 [.jshintrc](https://github.com/allmobilize/amazeui/blob/master/.jshintrc)[.jscsrc](https://github.com/allmobilize/amazeui/blob/master/.jscsrc)
详细设置参见 ~~[.jshintrc](https://github.com/amazeui/amazeui/blob/master/.jshintrc)[.jscsrc](https://github.com/amazeui/amazeui/blob/master/.jscsrc)~~[.eslintrc](https://github.com/amazeui/amazeui/blob/master/.eslintrc)

> 2016.04.20 替换为 ESLint,参见 [Welcoming JSCS to ESLint](http://eslint.org/blog/2016/04/welcoming-jscs-to-eslint)
(部分直接使用第三方库的代码未通过质量控制工具检测。)

Expand Down
2 changes: 2 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ var config = {
warnings: false
},
output: {
/* eslint-disable camelcase */
ascii_only: true
/* eslint-enable camelcase */
}
}
};
Expand Down
20 changes: 14 additions & 6 deletions js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ UI.support.animation = (function() {
return animationEnd && {end: animationEnd};
})();

/* eslint-disable dot-notation */
UI.support.touch = (
('ontouchstart' in window &&
navigator.userAgent.toLowerCase().match(/mobile|tablet/)) ||
(window.DocumentTouch && document instanceof window.DocumentTouch) ||
(window.navigator['msPointerEnabled'] &&
window.navigator['msMaxTouchPoints'] > 0) || //IE 10
window.navigator['msMaxTouchPoints'] > 0) || // IE 10
(window.navigator['pointerEnabled'] &&
window.navigator['maxTouchPoints'] > 0) || //IE >=11
window.navigator['maxTouchPoints'] > 0) || // IE >=11
false);
/* eslint-enable dot-notation */

// https://developer.mozilla.org/zh-CN/docs/DOM/MutationObserver
UI.support.mutationobserver = (window.MutationObserver ||
Expand Down Expand Up @@ -428,6 +430,7 @@ UI.template = function(id, data) {
me.get(id) : (name = 'template(string)', id); // no warnings

var line = 1;
/* eslint-disable max-len, quotes */
var body = ('try { ' + (me.variable ?
'var ' + me.variable + ' = this.stash;' : 'with (this.stash) { ') +
"this.ret += '" +
Expand All @@ -446,6 +449,7 @@ UI.template = function(id, data) {
"' + ' line ' + this.line + ')'; } " +
"//@ sourceURL=" + name + "\n" // source map
).replace(/this\.ret \+= '';/g, '');
/* eslint-enable max-len, quotes */
var func = new Function(body);
var map = {
'&': '&',
Expand Down Expand Up @@ -517,10 +521,10 @@ UI.DOMObserve = function(elements, options, callback) {
try {
var observer = new Observer(UI.utils.debounce(
function(mutations, instance) {
callback.call(element, mutations, instance);
// trigger this event manually if MutationObserver not supported
$element.trigger('changed.dom.amui');
}, 50));
callback.call(element, mutations, instance);
// trigger this event manually if MutationObserver not supported
$element.trigger('changed.dom.amui');
}, 50));

observer.observe(element, options);

Expand All @@ -532,7 +536,9 @@ UI.DOMObserve = function(elements, options, callback) {

$.fn.DOMObserve = function(options, callback) {
return this.each(function() {
/* eslint-disable new-cap */
UI.DOMObserve(this, options, callback);
/* eslint-enable new-cap */
});
};

Expand Down Expand Up @@ -564,7 +570,9 @@ $(function() {
});

// watches DOM
/* eslint-disable new-cap */
UI.DOMObserve('[data-am-observe]');
/* eslint-enable */

$html.removeClass('no-js').addClass('js');

Expand Down

0 comments on commit 8b54dc6

Please sign in to comment.