Skip to content

Commit 59da816

Browse files
committed
style: apply semistandard
1 parent c5f4943 commit 59da816

File tree

5 files changed

+272
-325
lines changed

5 files changed

+272
-325
lines changed

.jshintrc

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

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ unassertify
77

88
[![Build Status][ci-image]][ci-url]
99
[![NPM version][npm-image]][npm-url]
10+
[![Code Style][style-image]][style-url]
1011
[![License][license-image]][license-url]
1112

1213

@@ -158,3 +159,6 @@ Licensed under the [MIT](https://github.com/unassert-js/unassertify/blob/master/
158159

159160
[license-url]: https://github.com/unassert-js/unassertify/blob/master/LICENSE
160161
[license-image]: https://img.shields.io/badge/license-MIT-brightgreen.svg
162+
163+
[style-url]: https://github.com/standard/semistandard
164+
[style-image]: https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg

index.js

Lines changed: 76 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* unassertify
33
* Browserify transform for unassert
44
* Encourages programming with assertions by providing tools to compile them away.
5-
*
5+
*
66
* https://github.com/unassert-js/unassertify
77
*
88
* Copyright (c) 2015-2018 Takuto Wada
@@ -11,109 +11,110 @@
1111
*/
1212
'use strict';
1313

14-
var path = require('path');
15-
var through = require('through');
16-
var acorn = require('acorn');
17-
var escodegen = require('escodegen');
18-
var convert = require('convert-source-map');
19-
var transfer = require('multi-stage-sourcemap').transfer;
20-
var unassert = require('unassert');
14+
const path = require('path');
15+
const through = require('through');
16+
const acorn = require('acorn');
17+
const escodegen = require('escodegen');
18+
const convert = require('convert-source-map');
19+
const { transfer } = require('multi-stage-sourcemap');
20+
const unassert = require('unassert');
21+
const hasOwn = Object.prototype.hasOwnProperty;
2122

2223
function mergeSourceMap (incomingSourceMap, outgoingSourceMap) {
23-
if (typeof outgoingSourceMap === 'string' || outgoingSourceMap instanceof String) {
24-
outgoingSourceMap = JSON.parse(outgoingSourceMap);
25-
}
26-
if (!incomingSourceMap) {
27-
return outgoingSourceMap;
28-
}
29-
return JSON.parse(transfer({fromSourceMap: outgoingSourceMap, toSourceMap: incomingSourceMap}));
24+
if (typeof outgoingSourceMap === 'string' || outgoingSourceMap instanceof String) {
25+
outgoingSourceMap = JSON.parse(outgoingSourceMap);
26+
}
27+
if (!incomingSourceMap) {
28+
return outgoingSourceMap;
29+
}
30+
return JSON.parse(transfer({ fromSourceMap: outgoingSourceMap, toSourceMap: incomingSourceMap }));
3031
}
3132

3233
function overwritePropertyIfExists (name, from, to) {
33-
if (from.hasOwnProperty(name)) {
34-
to.setProperty(name, from[name]);
35-
}
34+
if (hasOwn.call(from, name)) {
35+
to.setProperty(name, from[name]);
36+
}
3637
}
3738

3839
function reconnectSourceMap (inMap, outMap) {
39-
var mergedRawMap = mergeSourceMap(inMap, outMap.toObject());
40-
var reMap = convert.fromObject(mergedRawMap);
41-
overwritePropertyIfExists('sources', inMap, reMap);
42-
overwritePropertyIfExists('sourceRoot', inMap, reMap);
43-
overwritePropertyIfExists('sourcesContent', inMap, reMap);
44-
return reMap;
40+
const mergedRawMap = mergeSourceMap(inMap, outMap.toObject());
41+
const reMap = convert.fromObject(mergedRawMap);
42+
overwritePropertyIfExists('sources', inMap, reMap);
43+
overwritePropertyIfExists('sourceRoot', inMap, reMap);
44+
overwritePropertyIfExists('sourcesContent', inMap, reMap);
45+
return reMap;
4546
}
4647

4748
function handleIncomingSourceMap (originalCode) {
48-
var commented = convert.fromSource(originalCode);
49-
if (commented) {
50-
return commented.toObject();
51-
}
52-
return null;
49+
const commented = convert.fromSource(originalCode);
50+
if (commented) {
51+
return commented.toObject();
52+
}
53+
return null;
5354
}
5455

5556
function applyUnassertWithSourceMap (code, filepath) {
56-
var ast = acorn.parse(code, {
57-
sourceType: 'module',
58-
ecmaVersion: 2018,
59-
locations: true,
60-
allowHashBang: true
61-
});
62-
var inMap = handleIncomingSourceMap(code);
63-
var instrumented = escodegen.generate(unassert(ast), {
64-
sourceMap: filepath,
65-
sourceContent: code,
66-
sourceMapWithCode: true
67-
});
68-
var outMap = convert.fromJSON(instrumented.map.toString());
69-
if (inMap) {
70-
var reMap = reconnectSourceMap(inMap, outMap);
71-
return instrumented.code + '\n' + reMap.toComment() + '\n';
72-
} else {
73-
return instrumented.code + '\n' + outMap.toComment() + '\n';
74-
}
57+
const ast = acorn.parse(code, {
58+
sourceType: 'module',
59+
ecmaVersion: 2018,
60+
locations: true,
61+
allowHashBang: true
62+
});
63+
const inMap = handleIncomingSourceMap(code);
64+
const instrumented = escodegen.generate(unassert(ast), {
65+
sourceMap: filepath,
66+
sourceContent: code,
67+
sourceMapWithCode: true
68+
});
69+
const outMap = convert.fromJSON(instrumented.map.toString());
70+
if (inMap) {
71+
const reMap = reconnectSourceMap(inMap, outMap);
72+
return instrumented.code + '\n' + reMap.toComment() + '\n';
73+
} else {
74+
return instrumented.code + '\n' + outMap.toComment() + '\n';
75+
}
7576
}
7677

7778
function applyUnassertWithoutSourceMap (code) {
78-
var ast = acorn.parse(code, {
79-
sourceType: 'module',
80-
ecmaVersion: 2018,
81-
allowHashBang: true
82-
});
83-
return escodegen.generate(unassert(ast));
79+
const ast = acorn.parse(code, {
80+
sourceType: 'module',
81+
ecmaVersion: 2018,
82+
allowHashBang: true
83+
});
84+
return escodegen.generate(unassert(ast));
8485
}
8586

8687
function shouldProduceSourceMap (options) {
87-
return (options && options._flags && options._flags.debug);
88+
return (options && options._flags && options._flags.debug);
8889
}
8990

9091
function containsAssertions (src) {
91-
// Matches both `assert` and `power-assert`.
92-
return src.indexOf('assert') !== -1;
92+
// Matches both `assert` and `power-assert`.
93+
return src.indexOf('assert') !== -1;
9394
}
9495

9596
module.exports = function unassertify (filepath, options) {
96-
if (path.extname(filepath) === '.json') {
97-
return through();
98-
}
97+
if (path.extname(filepath) === '.json') {
98+
return through();
99+
}
99100

100-
var data = '',
101-
stream = through(write, end);
101+
let data = '';
102+
const stream = through(write, end);
102103

103-
function write(buf) {
104-
data += buf;
105-
}
104+
function write (buf) {
105+
data += buf;
106+
}
106107

107-
function end() {
108-
if (!containsAssertions(data)) {
109-
stream.queue(data);
110-
} else if (shouldProduceSourceMap(options)) {
111-
stream.queue(applyUnassertWithSourceMap(data, filepath));
112-
} else {
113-
stream.queue(applyUnassertWithoutSourceMap(data));
114-
}
115-
stream.queue(null);
108+
function end () {
109+
if (!containsAssertions(data)) {
110+
stream.queue(data);
111+
} else if (shouldProduceSourceMap(options)) {
112+
stream.queue(applyUnassertWithSourceMap(data, filepath));
113+
} else {
114+
stream.queue(applyUnassertWithoutSourceMap(data));
116115
}
116+
stream.queue(null);
117+
}
117118

118-
return stream;
119+
return stream;
119120
};

package.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
"coffeeify": "^3.0.0",
2828
"event-stream": "^4.0.0",
2929
"intelli-espower-loader": "^1.0.1",
30-
"jshint": "^2.9.3",
3130
"mocha": "^10.0.0",
32-
"power-assert": "^1.4.1"
31+
"power-assert": "^1.4.1",
32+
"semistandard": "^16.0.0",
33+
"snazzy": "^9.0.0"
3334
},
3435
"files": [
3536
"README.md",
@@ -54,7 +55,16 @@
5455
"url": "https://github.com/unassert-js/unassertify.git"
5556
},
5657
"scripts": {
57-
"lint": "jshint index.js",
58+
"fmt": "semistandard --fix index.js 'test/*.js'",
59+
"lint": "semistandard --verbose index.js 'test/*.js' | snazzy",
5860
"test": "npm run lint && mocha --require intelli-espower-loader"
61+
},
62+
"semistandard": {
63+
"globals": [
64+
"describe",
65+
"context",
66+
"beforeEach",
67+
"it"
68+
]
5969
}
6070
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy