Skip to content

Commit ecd20bf

Browse files
committed
new eslint rules, cleaned up code.
1 parent 350c02d commit ecd20bf

File tree

16 files changed

+938
-263
lines changed

16 files changed

+938
-263
lines changed

.editorconfig

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This project uses EditorConfig for setting code formatting options: http://editorconfig.org
1+
# This project uses EditorConfig for setting code formatting options: http://EditorConfig.org
22

33
root = true
44

@@ -14,7 +14,7 @@ tab_width = 4
1414
max_line_length = 120
1515

1616
spaces_around_operators = true
17-
spaces_around_brackets = inside
17+
spaces_around_brackets = none
1818
curly_bracket_next_line = true
1919
indent_brace_style = Allman
2020
continuation_indent_size = 4
@@ -24,13 +24,8 @@ curly_bracket_next_line = false
2424
continuation_indent_size = 0
2525

2626
[*.yml]
27-
indent_style = space
2827
indent_size = 2
2928

30-
[*.{js,json}]
31-
indent_style = space
32-
indent_size = 4
33-
3429
# Special overrides for automatically-generated files
3530
[package.json]
3631
indent_size = 2

.eslintrc

Lines changed: 0 additions & 47 deletions
This file was deleted.

.eslintrc.js

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
module.exports = {
2+
"env": {
3+
"node": true,
4+
"commonjs": true,
5+
"es6": true
6+
},
7+
"extends": [
8+
"eslint:recommended"
9+
],
10+
"parserOptions": {
11+
"ecmaVersion": 2018
12+
},
13+
"rules": {
14+
// Bad Practices
15+
"curly": "error",
16+
"no-await-in-loop": "error",
17+
"no-eval": "error",
18+
"no-implicit-globals": "error",
19+
"no-lone-blocks": "error",
20+
"no-return-await": "error",
21+
"no-self-compare": "error",
22+
"no-sequences": "error",
23+
"no-throw-literal": "error",
24+
"no-with": "error",
25+
"prefer-arrow-callback": [ "error", { "allowNamedFunctions": true } ],
26+
"prefer-promise-reject-errors": "error",
27+
"prefer-rest-params": "warn",
28+
"no-label-var": "error",
29+
"no-undefined": "off",
30+
"no-use-before-define": "error",
31+
"no-array-constructor": "error",
32+
"no-new-object": "error",
33+
"no-continue": "error",
34+
"no-unneeded-ternary": "error",
35+
"complexity": [ "error", 70 ],
36+
37+
// Common Mistakes
38+
"no-extra-bind": "warn",
39+
"no-floating-decimal": "warn",
40+
"no-multi-spaces": "warn",
41+
"no-useless-call": "warn",
42+
"no-useless-return": "warn",
43+
"require-await": "off",
44+
"no-mixed-operators": "warn",
45+
46+
// Style
47+
"array-bracket-newline": [ "warn", "consistent" ],
48+
"array-bracket-spacing": [ "warn", "always" ],
49+
"array-element-newline": [ "warn", "consistent" ],
50+
"arrow-parens": [ "warn", "always" ],
51+
"arrow-spacing": "warn",
52+
"block-spacing": "warn",
53+
"brace-style": [ "warn", "allman", { "allowSingleLine": true } ],
54+
"camelcase": "warn",
55+
"comma-dangle": [ "warn", "never" ],
56+
"comma-spacing": [ "warn", { "before": false, "after": true } ],
57+
"comma-style": [ "warn", "last" ],
58+
"computed-property-spacing": [ "warn", "never" ],
59+
"consistent-this": [ "warn", "self" ],
60+
"eol-last": [ "warn", "always" ],
61+
"func-call-spacing": ["warn", "never"],
62+
"func-style": [ "warn", "declaration", { "allowArrowFunctions": true } ],
63+
"function-paren-newline": [ "warn", "multiline" ],
64+
"generator-star-spacing": [ "warn", { "before": true, "after": false } ],
65+
"id-length": [ "warn", { "min": 2, "exceptions": [ "$", "_", "i", "x", "y", "z" ] } ],
66+
"indent": [
67+
"warn",
68+
4,
69+
{
70+
"SwitchCase": 1,
71+
"VariableDeclarator": 1,
72+
"outerIIFEBody": 1,
73+
"MemberExpression": 1,
74+
"FunctionDeclaration": {
75+
"parameters": 1,
76+
"body": 1
77+
},
78+
"FunctionExpression": {
79+
"parameters": 1,
80+
"body": 1
81+
},
82+
"CallExpression": {
83+
"arguments": 1
84+
},
85+
"ArrayExpression": 1,
86+
"ObjectExpression": 1,
87+
"ImportDeclaration": 1,
88+
"flatTernaryExpressions": false
89+
}
90+
],
91+
"key-spacing": [ "warn", { "beforeColon": false, "afterColon": true } ],
92+
"keyword-spacing": [
93+
"warn",
94+
{
95+
"overrides": {
96+
"if": { "after": false },
97+
"for": { "after": false },
98+
"while": { "after": false }
99+
}
100+
}
101+
],
102+
"lines-between-class-members": [ "warn", "always", { exceptAfterSingleLine: true } ],
103+
"new-parens": "warn",
104+
"newline-per-chained-call": [ "warn", { "ignoreChainWithDepth": 2 } ],
105+
"no-confusing-arrow": [ "warn", { "allowParens": false } ],
106+
"no-duplicate-imports": "warn",
107+
"no-lonely-if": "warn",
108+
"no-multi-assign": "warn",
109+
"no-multiple-empty-lines": [ "warn", { "max": 1, "maxBOF": 0, "maxEOF": 1 } ],
110+
"no-trailing-spaces": "warn",
111+
"no-useless-computed-key": "warn",
112+
"no-useless-rename": [
113+
"error",
114+
{
115+
"ignoreDestructuring": false,
116+
"ignoreImport": false,
117+
"ignoreExport": false
118+
}
119+
],
120+
"no-var": "warn",
121+
"no-whitespace-before-property": "warn",
122+
"object-curly-spacing": [ "warn", "always" ],
123+
"object-property-newline": [ "warn", { "allowAllPropertiesOnSameLine": true } ],
124+
"object-shorthand": [ "warn", "always" ],
125+
"one-var": [ "warn", "never" ],
126+
"operator-linebreak": [ "warn", "before" ],
127+
"padded-blocks": [ "warn", "never" ],
128+
"prefer-const": "warn",
129+
"prefer-object-spread": "warn",
130+
"prefer-template": "warn",
131+
"quote-props": [ "warn", "consistent-as-needed" ],
132+
"quotes": [ "warn", "single", { "avoidEscape": true, "allowTemplateLiterals": true } ],
133+
"semi": [ "error", "always" ],
134+
"semi-spacing": [ "warn", { "before": false, "after": true } ],
135+
"space-before-blocks": "warn",
136+
"space-before-function-paren": [ "warn", "never" ],
137+
"space-in-parens": [ "warn", "never" ],
138+
"space-infix-ops": "warn",
139+
"space-unary-ops": "warn",
140+
"spaced-comment": [
141+
"warn",
142+
"always", {
143+
"line": {
144+
"markers": [ "/" ],
145+
"exceptions": [ "-", "+" ]
146+
},
147+
"block": {
148+
"markers": ["!"],
149+
"exceptions": ["*"],
150+
"balanced": true
151+
}
152+
}
153+
],
154+
"switch-colon-spacing": "warn",
155+
"template-curly-spacing": [ "warn", "always" ],
156+
"template-tag-spacing": "warn",
157+
"valid-jsdoc": [
158+
"warn",
159+
{
160+
"prefer": {
161+
"arg": "param",
162+
"argument": "param",
163+
"class": "class",
164+
"return": "returns",
165+
"virtual": "abstract"
166+
},
167+
"preferType": {
168+
"Boolean": "boolean",
169+
"Number": "number",
170+
"Object": "object",
171+
"String": "string"
172+
},
173+
"requireReturn": true,
174+
"requireParamDescription": true,
175+
"requireParamType": true
176+
}
177+
],
178+
"yield-star-spacing": [ "warn", "before" ],
179+
"yoda": [ "warn", "never", { "exceptRange": true } ]
180+
}
181+
};

lib/errors.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class TDBError extends BaseError
1616
this.name = this.constructor.name;
1717

1818
// Set a code property to allow the error to be easily identified. This is in keeping with current nodejs.
19-
this.code = !!code ? code : 'ERR_TDB_ERROR';
19+
this.code = code ? code : 'ERR_TDB_ERROR';
2020
} // end constructor
2121

2222
toJSON()
@@ -31,7 +31,7 @@ class NotImplementedError extends TDBError
3131
{
3232
constructor(api)
3333
{
34-
super(`'${api}' is not implemented.`, 'TDB_NOT_IMPLEMENTED');
34+
super(`'${ api }' is not implemented.`, 'TDB_NOT_IMPLEMENTED');
3535
} // end constructor
3636
} // end NotImplemented Error
3737

@@ -41,7 +41,7 @@ class DocumentNotFoundError extends TDBError
4141
{
4242
constructor(doc)
4343
{
44-
super(`Document with id '${doc}' not found.`, 'TDB_DOC_NOT_FOUND');
44+
super(`Document with id '${ doc }' not found.`, 'TDB_DOC_NOT_FOUND');
4545
this.doc = doc;
4646
} // end constructor
4747
} // end DocumentNotFoundError
@@ -63,7 +63,7 @@ class WriteDatabaseError extends TDBError
6363
{
6464
constructor(error, path)
6565
{
66-
super(`Error writing database('${ path }'): ${error}`, 'TDB_WRITE_DB');
66+
super(`Error writing database('${ path }'): ${ error }`, 'TDB_WRITE_DB');
6767
this.innerError = error;
6868
this.path = path;
6969
} // end constructor

lib/fslib.browser.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
// fs operations for the browser
33
//----------------------------------------------------------------------------------------------------------------------
44

5-
const Promise = require('bluebird');
6-
7-
// Errors
8-
const { UnsupportedInBrowserError } = require('./errors');
9-
10-
//----------------------------------------------------------------------------------------------------------------------
5+
/* global fetch */
116

127
function readDB(path)
138
{
@@ -27,11 +22,11 @@ function readDB(path)
2722
function writeDB(path, jsonStr)
2823
{
2924
return fetch(path, {
30-
method: 'POST',
31-
mode: 'cors',
32-
headers: { 'Content-Type': 'application/json' },
33-
body: jsonStr
34-
})
25+
method: 'POST',
26+
mode: 'cors',
27+
headers: { 'Content-Type': 'application/json' },
28+
body: jsonStr
29+
})
3530
.then((data) => data.json())
3631
.catch((err) =>
3732
{

lib/fslib.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const statAsync = Promise.promisify(fs.stat);
1111
const writeFileAsync = Promise.promisify(fs.writeFile);
1212
const readFileAsync = Promise.promisify(fs.readFile);
1313

14+
const { WriteDatabaseError } = require('./errors');
15+
1416
//----------------------------------------------------------------------------------------------------------------------
1517

1618
function readDB(path)
@@ -22,10 +24,10 @@ function readDB(path)
2224
{
2325
return JSON.parse(jsonStr);
2426
}
25-
catch(ex)
27+
catch (ex)
2628
{
2729
// Wrap the exception in a more friendly one.
28-
const error = new Error("Failed to parse on disk json file.");
30+
const error = new Error('Failed to parse on disk json file.');
2931
error.code = 'ERR_JSON_PARSE';
3032
error.innerException = ex;
3133

@@ -43,7 +45,7 @@ function writeDB(path, jsonStr)
4345
{
4446
if(!stats.isDirectory())
4547
{
46-
throw new WriteDatabaseError("Root path " + JSON.stringify(rootPath) + " is not a directory!", path);
48+
throw new WriteDatabaseError(`Root path ${ JSON.stringify(rootPath) } is not a directory!`, path);
4749
} // end if
4850
})
4951
.catch((error) => { return error.code === 'ENOENT'; }, () => mkdirp(rootPath))

lib/namespace.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const TDB = require('./tdb');
88

99
//----------------------------------------------------------------------------------------------------------------------
1010

11-
class TDBNamespace {
11+
class TDBNamespace
12+
{
1213
constructor(name, options)
1314
{
1415
options = options || {};
@@ -23,7 +24,7 @@ class TDBNamespace {
2324
this._dbInstances = {};
2425
} // end constructor
2526

26-
get rootPath(){ return pathlib.join(this.basePath, this.dbPath, this.name); }
27+
get rootPath() { return pathlib.join(this.basePath, this.dbPath, this.name); }
2728

2829
db(name, options)
2930
{

lib/pathlib.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const path = require('path');
1010
* Gets the absolute path to the root folder of the currently running node process, or the folder it was run from. If
1111
* running in a browser, we simple return `'/'`, as that is always the root of a website.
1212
*
13-
* @returns {String} The path to the root folder of the current node process.
13+
* @returns {string} The path to the root folder of the current node process.
1414
*/
1515
function getRoot()
1616
{

0 commit comments

Comments
 (0)