Skip to content

Commit 22d8297

Browse files
committed
Updated formatting
1 parent 0ec8220 commit 22d8297

20 files changed

+524
-623
lines changed

.eslintrc

Lines changed: 17 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,17 @@
1-
extends:
2-
airbnb
3-
4-
env:
5-
es6: true
6-
node: true
7-
mocha: true
8-
browser: true
9-
10-
parserOptions:
11-
sourceType: module
12-
13-
rules:
14-
quotes:
15-
- error
16-
- single
17-
- avoid-escape
18-
semi:
19-
- error
20-
- never
21-
no-empty:
22-
- error
23-
- allowEmptyCatch: true
24-
no-use-before-define:
25-
- off
26-
- nofunc
27-
one-var:
28-
- off
29-
eqeqeq:
30-
- error
31-
- smart
32-
no-unused-vars:
33-
- error
34-
no-param-reassign:
35-
- off
36-
no-cond-assign:
37-
- error
38-
- except-parens
39-
arrow-parens:
40-
- error
41-
- as-needed
42-
object-curly-spacing:
43-
- off
44-
no-underscore-dangle:
45-
- off
46-
class-methods-use-this:
47-
- off
48-
arrow-body-style:
49-
- off
50-
padded-blocks:
51-
- off
52-
global-require:
53-
- off
54-
no-restricted-syntax:
55-
- error
56-
- WithStatement
57-
no-unused-expressions:
58-
- off
59-
func-names:
60-
- off
61-
space-before-function-paren:
62-
- off
63-
block-spacing:
64-
- off
65-
space-infix-ops:
66-
- off
67-
consistent-return:
68-
- off
69-
no-shadow:
70-
- off
71-
no-console:
72-
- off
73-
no-continue:
74-
- off
75-
no-prototype-builtins:
76-
- off
77-
no-lonely-if:
78-
- off
79-
no-confusing-arrow:
80-
- off
81-
import/no-dynamic-require:
82-
- off
83-
import/newline-after-import:
84-
- off
85-
import/prefer-default-export:
86-
- off
1+
{
2+
"parser": "babel-eslint",
3+
"extends": [
4+
"standard",
5+
],
6+
"env": {
7+
"mocha": true
8+
},
9+
"rules": {
10+
"no-prototype-builtins": "off",
11+
"space-before-function-paren": "off",
12+
"comma-dangle": ["error", {
13+
"arrays": "always-multiline",
14+
"objects": "always-multiline"
15+
}]
16+
}
17+
}

.huskyrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"hooks": {
3+
"pre-commit": "npm run test"
4+
}
5+
}

.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"trailingComma": "es5",
5+
"printWidth": 100
6+
}

package.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
"build:dist": "webpack --progress --hide-modules",
1919
"build:dist-min": "NODE_ENV=production webpack --progress --hide-modules",
2020
"coveralls": "cat ./coverage/lcov.info | coveralls",
21-
"lint": "eslint src test",
21+
"format": "prettier --write '{src,test}/**/*.js' && eslint --fix '{src,test}/**/*.js'",
22+
"lint": "prettier --check '{src,test}/**/*.js' && eslint '{src,test}/**/*.js'",
2223
"prepublish": "npm run build",
23-
"prepush": "npm run test",
2424
"pretest": "npm run lint",
2525
"profiles": "npm run profiles:registry && npm run profiles:data-package && npm run profiles:tabular-data-package && npm run profiles:fiscal-data-package && npm run profiles:data-resource && npm run profiles:tabular-data-resource",
2626
"profiles:registry": "wget -O src/profiles/registry.json https://specs.frictionlessdata.io/schemas/registry.json",
@@ -51,6 +51,7 @@
5151
"axios-mock-adapter": "^1.8.1",
5252
"babel": "^6.5.2",
5353
"babel-cli": "^6.24.1",
54+
"babel-eslint": "^10.1.0",
5455
"babel-istanbul": "^0.12.2",
5556
"babel-loader": "^6.2.1",
5657
"babel-plugin-istanbul": "^3.1.2",
@@ -65,11 +66,13 @@
6566
"chai": "^3.5.0",
6667
"coveralls": "^3.0.6",
6768
"doctoc": "^1.4.0",
68-
"eslint": "^4.19.1",
69-
"eslint-config-airbnb": "^13.0.0",
70-
"eslint-plugin-import": "^2.2.0",
71-
"eslint-plugin-jsx-a11y": "2.2.3",
72-
"eslint-plugin-react": "^6.8.0",
69+
"eslint": "^6.8.0",
70+
"eslint-config-standard": "^14.1.0",
71+
"eslint-plugin-import": "^2.20.0",
72+
"eslint-plugin-node": "^11.0.0",
73+
"eslint-plugin-promise": "^4.2.1",
74+
"eslint-plugin-react": "^7.18.3",
75+
"eslint-plugin-standard": "^4.0.1",
7376
"husky": "^3.0.8",
7477
"jsdom": "^15.1.1",
7578
"json-loader": "^0.5.4",
@@ -82,6 +85,7 @@
8285
"mocha": "^6.2.1",
8386
"mocha-lcov-reporter": "^1.2.0",
8487
"nyc": "^14.1.1",
88+
"prettier": "^2.0.2",
8589
"referencer": "^0.2.5",
8690
"sinon": "^2.1.0",
8791
"sinon-chai": "^2.9.0",

src/config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Module API
22

3-
const IS_BROWSER = (typeof window !== 'undefined')
3+
const IS_BROWSER = typeof window !== 'undefined'
44
const TABULAR_FORMATS = ['csv', 'tsv', 'xls', 'xlsx']
55
const DEFAULT_DATA_PACKAGE_PROFILE = 'data-package'
66
const DEFAULT_RESOURCE_PROFILE = 'data-resource'
@@ -18,7 +18,6 @@ const DEFAULT_DIALECT = {
1818
caseSensitiveHeader: false,
1919
}
2020

21-
2221
// System
2322

2423
module.exports = {

src/errors.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const tableschema = require('tableschema')
22

3-
43
// Module API
54

65
/**
@@ -13,7 +12,6 @@ const DataPackageError = tableschema.errors.DataPackageError
1312
*/
1413
const TableSchemaError = tableschema.errors.TableSchemaError
1514

16-
1715
// System
1816

1917
module.exports = {

src/helpers.js

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ const isString = require('lodash/isString')
55
const cloneDeep = require('lodash/cloneDeep')
66
const isPlainObject = require('lodash/isPlainObject')
77
const jsonpointer = require('json-pointer')
8-
const {DataPackageError} = require('./errors')
8+
const { DataPackageError } = require('./errors')
99
const config = require('./config')
1010
const omit = require('lodash/omit')
1111

12-
1312
// Locate descriptor
1413

1514
function locateDescriptor(descriptor) {
@@ -19,23 +18,21 @@ function locateDescriptor(descriptor) {
1918
if (isString(descriptor)) {
2019
basePath = descriptor.split('/').slice(0, -1).join('/') || '.'
2120

22-
// Current dir by default
21+
// Current dir by default
2322
} else {
2423
basePath = '.'
2524
}
2625

2726
return basePath
2827
}
2928

30-
3129
// Retrieve descriptor
3230

3331
async function retrieveDescriptor(descriptor) {
3432
if (isPlainObject(descriptor)) {
3533
return cloneDeep(descriptor)
3634
}
3735
if (isString(descriptor)) {
38-
3936
// Remote
4037
if (isRemotePath(descriptor)) {
4138
try {
@@ -46,7 +43,7 @@ async function retrieveDescriptor(descriptor) {
4643
throw new DataPackageError(message)
4744
}
4845

49-
// Local
46+
// Local
5047
} else {
5148
if (config.IS_BROWSER) {
5249
const message = `Local descriptor "${descriptor}" in browser is not supported`
@@ -61,25 +58,25 @@ async function retrieveDescriptor(descriptor) {
6158
throw new DataPackageError(message)
6259
}
6360
}
64-
6561
}
6662
throw new DataPackageError('Descriptor must be String or Object')
6763
}
6864

69-
7065
// Dereference descriptor
7166

7267
async function dereferencePackageDescriptor(descriptor, basePath) {
7368
descriptor = cloneDeep(descriptor)
7469
for (const [index, resource] of (descriptor.resources || []).entries()) {
7570
// TODO: May be we should use Promise.all here
7671
descriptor.resources[index] = await dereferenceResourceDescriptor(
77-
resource, basePath, descriptor)
72+
resource,
73+
basePath,
74+
descriptor
75+
)
7876
}
7977
return descriptor
8078
}
8179

82-
8380
async function dereferenceResourceDescriptor(descriptor, basePath, baseDescriptor) {
8481
descriptor = cloneDeep(descriptor)
8582
baseDescriptor = baseDescriptor || descriptor
@@ -91,7 +88,7 @@ async function dereferenceResourceDescriptor(descriptor, basePath, baseDescripto
9188
if (!isString(value)) {
9289
continue
9390

94-
// URI -> Pointer
91+
// URI -> Pointer
9592
} else if (value.startsWith('#')) {
9693
try {
9794
descriptor[property] = jsonpointer.get(baseDescriptor, value.slice(1))
@@ -100,7 +97,7 @@ async function dereferenceResourceDescriptor(descriptor, basePath, baseDescripto
10097
throw new DataPackageError(message)
10198
}
10299

103-
// URI -> Remote
100+
// URI -> Remote
104101
} else {
105102
if (basePath && isRemotePath(basePath)) {
106103
// TODO: support other that Unix OS
@@ -115,7 +112,7 @@ async function dereferenceResourceDescriptor(descriptor, basePath, baseDescripto
115112
throw new DataPackageError(message)
116113
}
117114

118-
// URI -> Local
115+
// URI -> Local
119116
} else {
120117
if (config.IS_BROWSER) {
121118
const message = 'Local URI dereferencing in browser is not supported'
@@ -146,7 +143,6 @@ async function dereferenceResourceDescriptor(descriptor, basePath, baseDescripto
146143
return descriptor
147144
}
148145

149-
150146
// Expand descriptor
151147

152148
function expandPackageDescriptor(descriptor) {
@@ -158,17 +154,15 @@ function expandPackageDescriptor(descriptor) {
158154
return descriptor
159155
}
160156

161-
162157
function expandResourceDescriptor(descriptor) {
163158
descriptor = cloneDeep(descriptor)
164159
descriptor.profile = descriptor.profile || config.DEFAULT_RESOURCE_PROFILE
165160
descriptor.encoding = descriptor.encoding || config.DEFAULT_RESOURCE_ENCODING
166161
if (descriptor.profile === 'tabular-data-resource') {
167-
168162
// Schema
169163
const schema = descriptor.schema
170164
if (schema !== undefined) {
171-
for (const field of (schema.fields || [])) {
165+
for (const field of schema.fields || []) {
172166
field.type = field.type || config.DEFAULT_FIELD_TYPE
173167
field.format = field.format || config.DEFAULT_FIELD_FORMAT
174168
}
@@ -192,14 +186,18 @@ function expandResourceDescriptor(descriptor) {
192186

193187
// quoteChar and escapeChar are mutually exclusive: https://frictionlessdata.io/specs/csv-dialect/#specification
194188
function filterDefaultDialect(dialect = {}) {
195-
const defaultDialects = dialect.hasOwnProperty('escapeChar') ? omit(config.DEFAULT_DIALECT, 'quoteChar') : config.DEFAULT_DIALECT
189+
const defaultDialects = dialect.hasOwnProperty('escapeChar')
190+
? omit(config.DEFAULT_DIALECT, 'quoteChar')
191+
: config.DEFAULT_DIALECT
196192
return defaultDialects
197193
}
198194

199195
// quoteChar and escapeChar are mutually exclusive: https://frictionlessdata.io/specs/csv-dialect/#specification
200196
function validateDialect(dialect = {}) {
201197
if (dialect.hasOwnProperty('escapeChar') && dialect.hasOwnProperty('quoteChar')) {
202-
throw new DataPackageError('Resource.table dialect options quoteChar and escapeChar are mutually exclusive.')
198+
throw new DataPackageError(
199+
'Resource.table dialect options quoteChar and escapeChar are mutually exclusive.'
200+
)
203201
}
204202
return dialect
205203
}
@@ -209,10 +207,9 @@ function isRemotePath(path) {
209207
return path.startsWith('http')
210208
}
211209

212-
213210
function isSafePath(path) {
214-
const containsWindowsVar = path => path.match(/%.+%/)
215-
const containsPosixVar = path => path.match(/\$.+/)
211+
const containsWindowsVar = (path) => path.match(/%.+%/)
212+
const containsPosixVar = (path) => path.match(/\$.+/)
216213

217214
// Safety checks
218215
const unsafenessConditions = [
@@ -226,7 +223,6 @@ function isSafePath(path) {
226223
return !unsafenessConditions.some(Boolean)
227224
}
228225

229-
230226
// System
231227

232228
module.exports = {

src/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ const { Profile } = require('./profile')
55
const { validate } = require('./validate')
66
const { infer } = require('./infer')
77
const { DataPackageError } = require('./errors')
8-
const {TableSchemaError} = require('./errors')
9-
8+
const { TableSchemaError } = require('./errors')
109

1110
// Module API
1211

0 commit comments

Comments
 (0)