Merged in isqua/chrome_point_plus/code-style (pull request #14)

Code style checking
This commit is contained in:
isqua 2015-02-04 13:56:19 +03:00
commit 74c0e0319f
9 changed files with 236 additions and 43 deletions

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
chrome_point_plus/vendor/ chrome_point_plus/vendor/
/nbproject/private/ /nbproject/private/
node_modules/ node_modules/
npm-debug.log
publish publish
vendor/ vendor/

119
.jscs.json Normal file
View file

@ -0,0 +1,119 @@
{
"disallowImplicitTypeConversion": [ "numeric", "boolean", "binary" ],
"disallowKeywordsOnNewLine": [ "else" ],
"disallowMixedSpacesAndTabs": true,
"disallowMultipleLineBreaks": true,
"disallowMultipleLineStrings": true,
"disallowNewlineBeforeBlockStatements": true,
"disallowOperatorBeforeLineBreak": [ "+", "-", "*", "/", "." ],
"disallowPaddingNewlinesInBlocks": true,
"disallowQuotedKeysInObjects": "allButReserved",
"disallowSpaceAfterObjectKeys": true,
"disallowSpaceAfterPrefixUnaryOperators": [ "++", "--", "+", "-" ],
"disallowSpaceBeforePostfixUnaryOperators": true,
"disallowSpacesInCallExpression": true,
"disallowSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInsideParentheses": true,
"disallowTrailingComma": true,
"disallowTrailingWhitespace": true,
"disallowYodaConditions": true,
"requireBlocksOnNewline": true,
"requireCapitalizedConstructors": true,
"requireCommaBeforeLineBreak": true,
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
"requireDotNotation": true,
"requireLineBreakAfterVariableAssignment": true,
"requireLineFeedAtFileEnd": true,
"requirePaddingNewlinesBeforeKeywords": [
"do",
"for",
"if",
"switch",
"try",
"void",
"while",
"with",
"return"
],
"requireSpaceAfterBinaryOperators": true,
"requireSpaceAfterKeywords": [
"do",
"for",
"if",
"else",
"switch",
"case",
"try",
"catch",
"void",
"while",
"with",
"return",
"typeof"
],
"requireSpaceAfterLineComment": {
"allExcept": [ "#", "=" ]
},
"requireSpaceAfterPrefixUnaryOperators": [ "~", "!" ],
"requireSpaceBeforeBinaryOperators": [
"=",
"+",
"-",
"/",
"*",
"==",
"===",
"!=",
"!=="
],
"requireSpaceBeforeBlockStatements": true,
"requireSpaceBeforeKeywords": [
"else",
"while",
"catch"
],
"requireSpaceBeforeObjectValues": true,
"requireSpaceBetweenArguments": true,
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInForStatement": true,
"requireSpacesInFunctionDeclaration": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInNamedFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInsideObjectBrackets": "allButNested",
"validateIndentation": 4,
"validateLineBreaks": "LF",
"validateParameterSeparator": ", ",
"excludeFiles": [
"chrome_point_plus/js/bquery_ajax.js",
"chrome_point_plus/js/markitup/sets/markdown/set.js",
"chrome_point_plus/js/point-plus.js",
"chrome_point_plus/vendor/**",
"nbproject/**",
"node_modules/**",
"publish/**",
"vendor/**"
]
}

9
.jshintignore Normal file
View file

@ -0,0 +1,9 @@
.git/**
chrome_point_plus/js/bquery_ajax.js
chrome_point_plus/js/markitup/sets/markdown/set.js
chrome_point_plus/js/point-plus.js
chrome_point_plus/vendor/**
nbproject/**
node_modules/**
publish/**
vendor/**

26
.jshintrc Normal file
View file

@ -0,0 +1,26 @@
{
"bitwise": true,
"camelcase": false,
"curly": true,
"eqeqeq": true,
"es3": false,
"forin": true,
"freeze": true,
"latedef": true,
"maxlen": 120,
"maxparams": 4,
"newcap": true,
"noarg": true,
"noempty": true,
"nonbsp": true,
"quotmark": "single",
"shadow": "inner",
"undef": true,
"unused": true,
"browser": true,
"jquery": true,
"globals": {
"chrome": true,
"console": true
}
}

View file

@ -22,8 +22,8 @@ vendorCopy.push({
dest: 'chrome_point_plus/' dest: 'chrome_point_plus/'
}); });
/* global module */
module.exports = function(grunt) { module.exports = function(grunt) {
// Настройки // Настройки
grunt.initConfig({ grunt.initConfig({
pkg: grunt.file.readJSON('package.json'), pkg: grunt.file.readJSON('package.json'),
@ -46,7 +46,7 @@ module.exports = function(grunt) {
gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d', gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d',
globalReplace: true globalReplace: true
} }
}, }
}); });
// Загрузить плагины // Загрузить плагины

View file

@ -28,3 +28,30 @@
* Сразу присылать пулл-реквесты с шашкой наголо * Сразу присылать пулл-реквесты с шашкой наголо
* Поставить в магазинах Opera и Chrome оценку расширению * Поставить в магазинах Opera и Chrome оценку расширению
* Задонатить (см. таб Feedback в настройках) * Задонатить (см. таб Feedback в настройках)
### Как собрать из исходников
Для сборки используется Node.js. Ещё нужно глобально установить npm-пакет grunt-cli (`npm i -g grunt-cli`).
Все команды ниже нужно выполнять в корне проекта.
Установить npm и bower зависимости и разложить библиотеки по местам:
```
npm install
```
Если у вас нет Node.js, то вы можете посмотреть используемые библиотеки в файле `bower.json` и положить их
в `chrome_point_plus/vendor`.
Проверить кодстайл:
```
npm run lint
```
Поднять версию ([примеры](https://github.com/vojtajina/grunt-bump/blob/master/README.md#usage-examples)):
```
grunt bump
```

View file

@ -42,6 +42,7 @@ function injectFiles(files, injectOne, onAllInjected, results) {
* @constructor Менеджер сообщений * @constructor Менеджер сообщений
*/ */
function MessageListener() { function MessageListener() {
/* jshint unused:false */
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
if (this.isMethodAvailable(message)) { if (this.isMethodAvailable(message)) {
console.info('Call #%s() method for tab #%s', message.type, this.getTabId(sender)); console.info('Call #%s() method for tab #%s', message.type, this.getTabId(sender));
@ -54,6 +55,7 @@ function MessageListener() {
return false; return false;
} }
}.bind(this)); }.bind(this));
/* jshint unused:true */
} }
/** /**
@ -121,7 +123,7 @@ MessageListener.prototype.getManifestVersion = function(message, sender, sendRes
MessageListener.prototype.getFiles = function(message, defaultRunAt) { MessageListener.prototype.getFiles = function(message, defaultRunAt) {
var files; var files;
if ( ! message.files) { if (! message.files) {
return false; return false;
} else { } else {
files = Array.isArray(message.files) ? message.files : [ message.files ]; files = Array.isArray(message.files) ? message.files : [ message.files ];
@ -147,7 +149,7 @@ MessageListener.prototype.executeJSFiles = function(message, sender, sendRespons
injectFiles( injectFiles(
this.getFiles(message, 'document_end'), this.getFiles(message, 'document_end'),
function(file, callback) { function(file, callback) {
chrome.tabs.executeScript(tabId, file, callback) chrome.tabs.executeScript(tabId, file, callback);
}, },
sendResponse sendResponse
); );
@ -169,7 +171,6 @@ MessageListener.prototype.injectCSSFiles = function(message, sender, sendRespons
}, },
sendResponse sendResponse
); );
}; };
new MessageListener(); new MessageListener();
@ -185,6 +186,8 @@ chrome.storage.sync.get('options_version', function(data) {
// Adding notification click event listener // Adding notification click event listener
chrome.notifications.onClicked.addListener(function(notificationId) { chrome.notifications.onClicked.addListener(function(notificationId) {
var tab_url;
// Detecting notification type // Detecting notification type
if (notificationId.indexOf('comment_') === 0) { if (notificationId.indexOf('comment_') === 0) {
tab_url = 'https://point.im/' + notificationId.replace(/comment_/g, ''); tab_url = 'https://point.im/' + notificationId.replace(/comment_/g, '');

View file

@ -40,7 +40,8 @@ OptionsPage.prototype.updateOptionsFromFrom = function() {
}, function() { }, function() {
console.log('Default options initialized. Version upgraded to %s.', this.version); console.log('Default options initialized. Version upgraded to %s.', this.version);
if ( ! confirm(chrome.i18n.getMessage('options_text_new_version'))) { /* global confirm */
if (! confirm(chrome.i18n.getMessage('options_text_new_version'))) {
window.close(); window.close();
} }
}); });
@ -127,7 +128,7 @@ OptionsPage.prototype.updateOptionFromInput = function(input) {
this._options[key] = { this._options[key] = {
type: 'plain', type: 'plain',
value: input.value value: input.value
} };
} }
}; };
@ -188,12 +189,15 @@ OptionsPage.prototype.checkOldStyle = function() {
console.log('Found old-style options. Cleaning...'); console.log('Found old-style options. Cleaning...');
chrome.storage.sync.get(null, function(data) { chrome.storage.sync.get(null, function(data) {
var option;
console.log('Old data: %O', data); console.log('Old data: %O', data);
for (option in data) { for (option in data) {
if (data.hasOwnProperty(option)) {
chrome.storage.sync.remove(option); chrome.storage.sync.remove(option);
} }
}
console.log('All old data removed'); console.log('All old data removed');
}); });

View file

@ -4,7 +4,9 @@
"description": "Chrome extension for point.im", "description": "Chrome extension for point.im",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "postinstall": "./node_modules/.bin/bower install && grunt",
"lint": "./node_modules/.bin/jshint . && ./node_modules/.bin/jscs .",
"test": "npm run lint"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -16,6 +18,8 @@
"bower": "^1.3.12", "bower": "^1.3.12",
"grunt": "^0.4.5", "grunt": "^0.4.5",
"grunt-bump": "git://github.com/nkirkes/grunt-bump.git#nkirkes/restrict-version-key-name", "grunt-bump": "git://github.com/nkirkes/grunt-bump.git#nkirkes/restrict-version-key-name",
"grunt-contrib-copy": "^0.7.0" "grunt-contrib-copy": "^0.7.0",
"jscs": "^1.10.0",
"jshint": "^2.6.0"
} }
} }