switching to eslint for code checking

most rules degraded to WARN, so we don't go insane. This will
change over time. The aim is to conform to a common style

Signed-off-by: Claudius Coenen <opensource@amenthes.de>
This commit is contained in:
Claudius Coenen 2018-11-14 14:10:14 +01:00
parent f9aa001ee7
commit 858a59529e
13 changed files with 75 additions and 44 deletions

3
.eslintignore Normal file
View file

@ -0,0 +1,3 @@
lib/ot
public/vendor
public/build

21
.eslintrc.js Normal file
View file

@ -0,0 +1,21 @@
module.exports = {
"root": true,
"extends": "standard",
"env": {
"node": true
},
"rules": {
// at some point all of these should return to their default "error" state
// but right now, this is not a good choice, because too many places are
// wrong.
"import/first": ["warn"],
"indent": ["warn"],
"no-multiple-empty-lines": ["warn"],
"no-multi-spaces": ["warn"],
"object-curly-spacing": ["warn"],
"one-var": ["warn"],
"quotes": ["warn"],
"semi": ["warn"],
"space-infix-ops": ["warn"]
}
};

View file

@ -1,8 +1,6 @@
CodiMD CodiMD
=== ===
[![Standard - JavaScript Style Guide][standardjs-image]][standardjs-url]
[![#CodiMD on matrix.org][matrix.org-image]][matrix.org-url] [![#CodiMD on matrix.org][matrix.org-image]][matrix.org-url]
[![build status][travis-image]][travis-url] [![build status][travis-image]][travis-url]
[![version][github-version-badge]][github-release-page] [![version][github-version-badge]][github-release-page]
@ -373,7 +371,5 @@ See more at [http://operational-transformation.github.io/](http://operational-tr
[travis-url]: https://travis-ci.org/hackmdio/codimd [travis-url]: https://travis-ci.org/hackmdio/codimd
[github-version-badge]: https://img.shields.io/github/release/hackmdio/codimd.svg [github-version-badge]: https://img.shields.io/github/release/hackmdio/codimd.svg
[github-release-page]: https://github.com/hackmdio/codimd/releases [github-release-page]: https://github.com/hackmdio/codimd/releases
[standardjs-image]: https://cdn.rawgit.com/feross/standard/master/badge.svg
[standardjs-url]: https://github.com/feross/standard
[poeditor-image]: https://img.shields.io/badge/POEditor-translate-blue.svg [poeditor-image]: https://img.shields.io/badge/POEditor-translate-blue.svg
[poeditor-url]: https://poeditor.com/join/project/1OpGjF2Jir [poeditor-url]: https://poeditor.com/join/project/1OpGjF2Jir

View file

@ -25,6 +25,7 @@ if (config.dbURL) {
// https://github.com/sequelize/sequelize/issues/6485 // https://github.com/sequelize/sequelize/issues/6485
function stripNullByte (value) { function stripNullByte (value) {
value = '' + value value = '' + value
// eslint-disable-next-line no-control-regex
return value ? value.replace(/\u0000/g, '') : value return value ? value.replace(/\u0000/g, '') : value
} }
sequelize.stripNullByte = stripNullByte sequelize.stripNullByte = stripNullByte

View file

@ -50,7 +50,7 @@ module.exports = function (sequelize, DataTypes) {
}, { }, {
instanceMethods: { instanceMethods: {
verifyPassword: function (attempt) { verifyPassword: function (attempt) {
if (scrypt.verifyKdfSync(new Buffer(this.password, 'hex'), attempt)) { if (scrypt.verifyKdfSync(Buffer.from(this.password, 'hex'), attempt)) {
return this return this
} else { } else {
return false return false

View file

@ -242,6 +242,7 @@ function getStatus (callback) {
} }
}) })
models.User.count().then(function (regcount) { models.User.count().then(function (regcount) {
// eslint-disable-next-line standard/no-callback-literal
return callback ? callback({ return callback ? callback({
onlineNotes: Object.keys(notes).length, onlineNotes: Object.keys(notes).length,
onlineUsers: Object.keys(users).length, onlineUsers: Object.keys(users).length,
@ -283,7 +284,7 @@ function extractNoteIdFromSocket (socket) {
if (!referer) { if (!referer) {
return false return false
} }
var hostUrl = url.parse(referer) var hostUrl = url.URL.parse(referer)
var noteId = config.urlPath ? hostUrl.pathname.slice(config.urlPath.length + 1, hostUrl.pathname.length).split('/')[1] : hostUrl.pathname.split('/')[1] var noteId = config.urlPath ? hostUrl.pathname.slice(config.urlPath.length + 1, hostUrl.pathname.length).split('/')[1] : hostUrl.pathname.split('/')[1]
return noteId return noteId
} else { } else {

View file

@ -16,5 +16,5 @@ exports.uploadImage = function (imagePath, callback) {
return return
} }
callback(null, url.resolve(config.serverURL + '/uploads/', path.basename(imagePath))) callback(null, url.URL.resolve(config.serverURL + '/uploads/', path.basename(imagePath)))
} }

View file

@ -5,9 +5,10 @@
"main": "app.js", "main": "app.js",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"scripts": { "scripts": {
"test": "npm run-script standard && npm run-script jsonlint", "test": "npm run-script eslint && npm run-script jsonlint",
"eslint": "node_modules/.bin/eslint lib public app.js",
"jsonlint": "find . -not -path './node_modules/*' -type f -name '*.json' -o -type f -name '*.json.example' | while read json; do echo $json ; jq . $json; done", "jsonlint": "find . -not -path './node_modules/*' -type f -name '*.json' -o -type f -name '*.json.example' | while read json; do echo $json ; jq . $json; done",
"standard": "node ./node_modules/standard/bin/cmd.js", "standard": "echo 'standard is no longer being used, use `npm run eslint` instead!' && exit 1",
"dev": "webpack --config webpack.dev.js --progress --colors --watch", "dev": "webpack --config webpack.dev.js --progress --colors --watch",
"build": "webpack --config webpack.prod.js --progress --colors --bail", "build": "webpack --config webpack.prod.js --progress --colors --bail",
"postinstall": "bin/heroku", "postinstall": "bin/heroku",
@ -169,6 +170,12 @@
"css-loader": "^1.0.0", "css-loader": "^1.0.0",
"doctoc": "^1.3.0", "doctoc": "^1.3.0",
"ejs-loader": "^0.3.1", "ejs-loader": "^0.3.1",
"eslint": "^5.9.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"exports-loader": "^0.7.0", "exports-loader": "^0.7.0",
"expose-loader": "^0.7.5", "expose-loader": "^0.7.5",
"file-loader": "^2.0.0", "file-loader": "^2.0.0",
@ -180,7 +187,6 @@
"mini-css-extract-plugin": "^0.4.1", "mini-css-extract-plugin": "^0.4.1",
"optimize-css-assets-webpack-plugin": "^5.0.0", "optimize-css-assets-webpack-plugin": "^5.0.0",
"script-loader": "^0.7.2", "script-loader": "^0.7.2",
"standard": "^9.0.1",
"string-loader": "^0.0.1", "string-loader": "^0.0.1",
"style-loader": "^0.21.0", "style-loader": "^0.21.0",
"uglifyjs-webpack-plugin": "^1.2.7", "uglifyjs-webpack-plugin": "^1.2.7",
@ -190,34 +196,6 @@
"webpack-merge": "^4.1.4", "webpack-merge": "^4.1.4",
"webpack-parallel-uglify-plugin": "^1.1.0" "webpack-parallel-uglify-plugin": "^1.1.0"
}, },
"standard": {
"globals": [
"$",
"CodeMirror",
"Cookies",
"moment",
"editor",
"ui",
"Spinner",
"modeType",
"Idle",
"serverurl",
"key",
"gapi",
"Dropbox",
"FilePicker",
"ot",
"MediaUploader",
"hex2rgb",
"num_loaded",
"Visibility",
"inlineAttachment"
],
"ignore": [
"lib/ot",
"public/vendor"
]
},
"optionalDependencies": { "optionalDependencies": {
"bufferutil": "^4.0.0", "bufferutil": "^4.0.0",
"utf-8-validate": "^5.0.1" "utf-8-validate": "^5.0.1"

28
public/.eslintrc.js Normal file
View file

@ -0,0 +1,28 @@
// this config file is used in concert with the root .eslintrc.js in the root dir.
module.exports = {
"env": {
"browser": true
},
"globals": {
"$": false,
"CodeMirror": false,
"Cookies": false,
"moment": false,
"editor": false,
"ui": false,
"Spinner": false,
"modeType": false,
"Idle": false,
"serverurl": false,
"key": false,
"gapi": false,
"Dropbox": false,
"FilePicker": false,
"ot": false,
"MediaUploader": false,
"hex2rgb": false,
"num_loaded": false,
"Visibility": false,
"inlineAttachment": false
}
};

View file

@ -218,6 +218,7 @@ export function getStorageHistory (callback) {
if (typeof data === 'string') { data = JSON.parse(data) } if (typeof data === 'string') { data = JSON.parse(data) }
callback(data) callback(data)
} }
// eslint-disable-next-line standard/no-callback-literal
callback([]) callback([])
} }

View file

@ -2511,7 +2511,9 @@ function buildCursor (user) {
// editor actions // editor actions
function removeNullByte (cm, change) { function removeNullByte (cm, change) {
var str = change.text.join('\n') var str = change.text.join('\n')
// eslint-disable-next-line no-control-regex
if (/\u0000/g.test(str) && change.update) { if (/\u0000/g.test(str) && change.update) {
// eslint-disable-next-line no-control-regex
change.update(change.from, change.to, str.replace(/\u0000/g, '').split('\n')) change.update(change.from, change.to, str.replace(/\u0000/g, '').split('\n'))
} }
} }
@ -3046,7 +3048,7 @@ function checkInCode () {
function checkAbove (method) { function checkAbove (method) {
var cursor = editor.getCursor() var cursor = editor.getCursor()
var text = [] var text = []
for (var i = 0; i < cursor.line; i++) { // contain current line for (var i = 0; i < cursor.line; i++) { // contain current line
text.push(editor.getLine(i)) text.push(editor.getLine(i))
} }
text = text.join('\n') + '\n' + editor.getLine(cursor.line).slice(0, cursor.ch) text = text.join('\n') + '\n' + editor.getLine(cursor.line).slice(0, cursor.ch)

View file

@ -492,7 +492,7 @@ export default class Editor {
clearInterval(spellcheckTimer) clearInterval(spellcheckTimer)
} }
}, },
100, 100
) )
} }
} }
@ -514,7 +514,7 @@ export default class Editor {
} }
setOverrideBrowserKeymap () { setOverrideBrowserKeymap () {
var overrideBrowserKeymap = $( var overrideBrowserKeymap = $(
'.ui-preferences-override-browser-keymap label > input[type="checkbox"]', '.ui-preferences-override-browser-keymap label > input[type="checkbox"]'
) )
if (overrideBrowserKeymap.is(':checked')) { if (overrideBrowserKeymap.is(':checked')) {
Cookies.set('preferences-override-browser-keymap', true, { Cookies.set('preferences-override-browser-keymap', true, {
@ -529,10 +529,10 @@ export default class Editor {
setPreferences () { setPreferences () {
var overrideBrowserKeymap = $( var overrideBrowserKeymap = $(
'.ui-preferences-override-browser-keymap label > input[type="checkbox"]', '.ui-preferences-override-browser-keymap label > input[type="checkbox"]'
) )
var cookieOverrideBrowserKeymap = Cookies.get( var cookieOverrideBrowserKeymap = Cookies.get(
'preferences-override-browser-keymap', 'preferences-override-browser-keymap'
) )
if (cookieOverrideBrowserKeymap && cookieOverrideBrowserKeymap === 'true') { if (cookieOverrideBrowserKeymap && cookieOverrideBrowserKeymap === 'true') {
overrideBrowserKeymap.prop('checked', true) overrideBrowserKeymap.prop('checked', true)

View file

@ -67,7 +67,7 @@ export const getUIElements = () => ({
codemirrorScroll: $('.ui-edit-area .CodeMirror .CodeMirror-scroll'), codemirrorScroll: $('.ui-edit-area .CodeMirror .CodeMirror-scroll'),
codemirrorSizer: $('.ui-edit-area .CodeMirror .CodeMirror-sizer'), codemirrorSizer: $('.ui-edit-area .CodeMirror .CodeMirror-sizer'),
codemirrorSizerInner: $( codemirrorSizerInner: $(
'.ui-edit-area .CodeMirror .CodeMirror-sizer > div', '.ui-edit-area .CodeMirror .CodeMirror-sizer > div'
), ),
markdown: $('.ui-view-area .markdown-body'), markdown: $('.ui-view-area .markdown-body'),
resize: { resize: {