Skip to content

Commit

Permalink
style: integrate prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Dec 24, 2018
1 parent 0f2b227 commit 3a854ba
Show file tree
Hide file tree
Showing 26 changed files with 1,345 additions and 897 deletions.
15 changes: 4 additions & 11 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
root = true

[*]
indent_style = tab
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 233

[*.json]
indent_style = space
indent_size = 2

[*.yml]
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[test/cases/parsing/bom/bomfile.{css,js}]
charset = utf-8-bom

[*.md]
insert_final_newline = true
trim_trailing_whitespace = false
85 changes: 31 additions & 54 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,58 +1,35 @@
{
"root": true,
"plugins": ["node"],
"extends": ["eslint:recommended", "plugin:node/recommended"],
"env": {
"node": true
},
"rules": {
"quotes": ["error", "double"],
"no-undef": "error",
"no-extra-semi": "error",
"semi": "error",
"no-template-curly-in-string": "error",
"no-caller": "error",
"yoda": "error",
"eqeqeq": "error",
"global-require": "off",
"brace-style": "error",
"eol-last": "error",
"indent": ["error", "tab", { "SwitchCase": 1 }],
"no-extra-bind": "warn",
"no-empty": "off",
"no-multiple-empty-lines": "error",
"no-multi-spaces": "error",
"no-process-exit": "warn",
"space-in-parens": "error",
"no-trailing-spaces": "error",
"no-use-before-define": "off",
"no-unused-vars": ["error", {"args": "none"}],
"key-spacing": "error",
"space-infix-ops": "error",
"no-unsafe-negation": "error",
"no-loop-func": "warn",
"space-before-function-paren": ["error", "never"],
"space-before-blocks": "error",
"object-curly-spacing": ["error", "always"],
"keyword-spacing": ["error", {
"after": false,
"overrides": {
"try": {"after": true},
"else": {"after": true},
"throw": {"after": true},
"case": {"after": true},
"return": {"after": true},
"finally": {"after": true},
"do": {"after": true}
}
}],
"no-console": "off",
"valid-jsdoc": "error",
"no-var": "error",
"prefer-const": "error",
"prefer-arrow-callback": "error",
"root": true,
"plugins": ["node", "prettier"],
"extends": ["eslint:recommended", "plugin:node/recommended"],
"env": {
"node": true
},
"rules": {
"no-template-curly-in-string": "error",
"no-caller": "error",
"yoda": "error",
"eqeqeq": "error",
"no-extra-bind": "error",
"no-process-exit": "error",
"no-loop-func": "error",
"no-console": "off",
"valid-jsdoc": "error",
"no-var": "error",
"prefer-const": "error",
"prefer-arrow-callback": "error",
"object-shorthand": "error",

// Allow to use `assert` module
"node/no-deprecated-api": "off"
}
"node/no-deprecated-api": "off",

"prettier/prettier": [
"error",
{
"singleQuote": true,
"trailingComma": "es5",
"arrowParens": "always"
}
]
}
}
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "es5",
"arrowParens": "always"
}
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ environment:

clone_depth: 10

version: "{build}"
version: '{build}'
build: off
deploy: off

Expand All @@ -29,4 +29,4 @@ cache:
test_script:
- node --version
- npm --version
- cmd: "yarn travis"
- cmd: 'yarn travis'
19 changes: 11 additions & 8 deletions lib/getCurrentRequest.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"use strict";
'use strict';

function getCurrentRequest(loaderContext) {
if(loaderContext.currentRequest)
return loaderContext.currentRequest;
const request = loaderContext.loaders
.slice(loaderContext.loaderIndex)
.map(obj => obj.request)
.concat([loaderContext.resource]);
return request.join("!");
if (loaderContext.currentRequest) {
return loaderContext.currentRequest;
}

const request = loaderContext.loaders
.slice(loaderContext.loaderIndex)
.map((obj) => obj.request)
.concat([loaderContext.resource]);

return request.join('!');
}

module.exports = getCurrentRequest;
90 changes: 53 additions & 37 deletions lib/getHashDigest.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,69 @@
"use strict";
'use strict';

const baseEncodeTables = {
26: "abcdefghijklmnopqrstuvwxyz",
32: "123456789abcdefghjkmnpqrstuvwxyz", // no 0lio
36: "0123456789abcdefghijklmnopqrstuvwxyz",
49: "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ", // no lIO
52: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
58: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ", // no 0lIO
62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
64: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_"
26: 'abcdefghijklmnopqrstuvwxyz',
32: '123456789abcdefghjkmnpqrstuvwxyz', // no 0lio
36: '0123456789abcdefghijklmnopqrstuvwxyz',
49: 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ', // no lIO
52: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
58: '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ', // no 0lIO
62: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
64: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_',
};

function encodeBufferToBase(buffer, base) {
const encodeTable = baseEncodeTables[base];
if(!encodeTable) throw new Error("Unknown encoding base" + base);
const encodeTable = baseEncodeTables[base];
if (!encodeTable) {
throw new Error('Unknown encoding base' + base);
}

const readLength = buffer.length;
const readLength = buffer.length;
const Big = require('big.js');

const Big = require("big.js");
Big.RM = Big.DP = 0;
let b = new Big(0);
for(let i = readLength - 1; i >= 0; i--) {
b = b.times(256).plus(buffer[i]);
}
Big.RM = Big.DP = 0;
let b = new Big(0);

let output = "";
while(b.gt(0)) {
output = encodeTable[b.mod(base)] + output;
b = b.div(base);
}
for (let i = readLength - 1; i >= 0; i--) {
b = b.times(256).plus(buffer[i]);
}

Big.DP = 20;
Big.RM = 1;
let output = '';
while (b.gt(0)) {
output = encodeTable[b.mod(base)] + output;
b = b.div(base);
}

return output;
Big.DP = 20;
Big.RM = 1;

return output;
}

function getHashDigest(buffer, hashType, digestType, maxLength) {
hashType = hashType || "md5";
maxLength = maxLength || 9999;
const hash = require("crypto").createHash(hashType);
hash.update(buffer);
if(digestType === "base26" || digestType === "base32" || digestType === "base36" ||
digestType === "base49" || digestType === "base52" || digestType === "base58" ||
digestType === "base62" || digestType === "base64") {
return encodeBufferToBase(hash.digest(), digestType.substr(4)).substr(0, maxLength);
} else {
return hash.digest(digestType || "hex").substr(0, maxLength);
}
hashType = hashType || 'md5';
maxLength = maxLength || 9999;

const hash = require('crypto').createHash(hashType);

hash.update(buffer);

if (
digestType === 'base26' ||
digestType === 'base32' ||
digestType === 'base36' ||
digestType === 'base49' ||
digestType === 'base52' ||
digestType === 'base58' ||
digestType === 'base62' ||
digestType === 'base64'
) {
return encodeBufferToBase(hash.digest(), digestType.substr(4)).substr(
0,
maxLength
);
} else {
return hash.digest(digestType || 'hex').substr(0, maxLength);
}
}

module.exports = getHashDigest;
25 changes: 14 additions & 11 deletions lib/getOptions.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
"use strict";
'use strict';

const parseQuery = require("./parseQuery");
const parseQuery = require('./parseQuery');

function getOptions(loaderContext) {
const query = loaderContext.query;
if(typeof query === "string" && query !== "") {
return parseQuery(loaderContext.query);
}
if(!query || typeof query !== "object") {
// Not object-like queries are not supported.
return null;
}
return query;
const query = loaderContext.query;

if (typeof query === 'string' && query !== '') {
return parseQuery(loaderContext.query);
}

if (!query || typeof query !== 'object') {
// Not object-like queries are not supported.
return null;
}

return query;
}

module.exports = getOptions;
19 changes: 11 additions & 8 deletions lib/getRemainingRequest.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"use strict";
'use strict';

function getRemainingRequest(loaderContext) {
if(loaderContext.remainingRequest)
return loaderContext.remainingRequest;
const request = loaderContext.loaders
.slice(loaderContext.loaderIndex + 1)
.map(obj => obj.request)
.concat([loaderContext.resource]);
return request.join("!");
if (loaderContext.remainingRequest) {
return loaderContext.remainingRequest;
}

const request = loaderContext.loaders
.slice(loaderContext.loaderIndex + 1)
.map((obj) => obj.request)
.concat([loaderContext.resource]);

return request.join('!');
}

module.exports = getRemainingRequest;
22 changes: 11 additions & 11 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"use strict";
'use strict';

const getOptions = require("./getOptions");
const parseQuery = require("./parseQuery");
const stringifyRequest = require("./stringifyRequest");
const getRemainingRequest = require("./getRemainingRequest");
const getCurrentRequest = require("./getCurrentRequest");
const isUrlRequest = require("./isUrlRequest");
const urlToRequest = require("./urlToRequest");
const parseString = require("./parseString");
const getHashDigest = require("./getHashDigest");
const interpolateName = require("./interpolateName");
const getOptions = require('./getOptions');
const parseQuery = require('./parseQuery');
const stringifyRequest = require('./stringifyRequest');
const getRemainingRequest = require('./getRemainingRequest');
const getCurrentRequest = require('./getCurrentRequest');
const isUrlRequest = require('./isUrlRequest');
const urlToRequest = require('./urlToRequest');
const parseString = require('./parseString');
const getHashDigest = require('./getHashDigest');
const interpolateName = require('./interpolateName');

exports.getOptions = getOptions;
exports.parseQuery = parseQuery;
Expand Down
Loading

0 comments on commit 3a854ba

Please sign in to comment.