Skip to content

Add prettier #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "@segment/eslint-config/browser/legacy"
"extends": ["prettier", "@segment/eslint-config/browser/legacy"]
}
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Binaries
##

ESLINT := node_modules/.bin/eslint
KARMA := node_modules/.bin/karma

##
Expand Down Expand Up @@ -62,12 +61,12 @@ distclean: clean

# Lint JavaScript source files.
lint: install
@$(ESLINT) $(ALL_FILES)
yarn lint
.PHONY: lint

# Attempt to fix linting errors.
fmt: install
@$(ESLINT) --fix $(ALL_FILES)
yarn format
.PHONY: fmt

# Run browser unit tests in a browser.
Expand Down
87 changes: 54 additions & 33 deletions lib/protos.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,31 +133,35 @@ exports.map = function(options, key) {
return [];
}

return foldl(function(matchingValues, val, key) {
var compare;
var result;

if (mappingType === 'map') {
compare = key;
result = val;
}
return foldl(
function(matchingValues, val, key) {
var compare;
var result;

if (mappingType === 'map') {
compare = key;
result = val;
}

if (mappingType === 'array') {
compare = val;
result = val;
}
if (mappingType === 'array') {
compare = val;
result = val;
}

if (mappingType === 'mixed') {
compare = val.key;
result = val.value;
}
if (mappingType === 'mixed') {
compare = val.key;
result = val.value;
}

if (normalize(compare) === normalizedComparator) {
matchingValues.push(result);
}
if (normalize(compare) === normalizedComparator) {
matchingValues.push(result);
}

return matchingValues;
}, [], options);
return matchingValues;
},
[],
options
);
};

/**
Expand Down Expand Up @@ -236,9 +240,20 @@ exports.reset = function() {

exports.load = function(name, locals, callback) {
// Argument shuffling
if (typeof name === 'function') { callback = name; locals = null; name = null; }
if (name && typeof name === 'object') { callback = locals; locals = name; name = null; }
if (typeof locals === 'function') { callback = locals; locals = null; }
if (typeof name === 'function') {
callback = name;
locals = null;
name = null;
}
if (name && typeof name === 'object') {
callback = locals;
locals = name;
name = null;
}
if (typeof locals === 'function') {
callback = locals;
locals = null;
}

// Default arguments
name = name || 'library';
Expand All @@ -263,7 +278,7 @@ exports.load = function(name, locals, callback) {
if (!err) return callback();
self.debug('error loading "%s" error="%s"', self.name, err);
});
// TODO: hack until refactoring load-script
// TODO: hack until refactoring load-script
delete attrs.src;
each(function(val, key) {
el.setAttribute(key, val);
Expand All @@ -273,7 +288,7 @@ exports.load = function(name, locals, callback) {
el = loadIframe(attrs, callback);
break;
default:
// No default case
// No default case
}

return el;
Expand Down Expand Up @@ -415,7 +430,9 @@ function loadImage(attrs, fn) {
fn = fn || function() {};
var img = new Image();
img.onerror = error(fn, 'failed to load pixel', img);
img.onload = function() { fn(); };
img.onload = function() {
fn();
};
img.src = attrs.src;
img.width = 1;
img.height = 1;
Expand Down Expand Up @@ -452,10 +469,14 @@ function error(fn, message, img) {
*/

function render(template, locals) {
return foldl(function(attrs, val, key) {
attrs[key] = val.replace(/\{\{\ *(\w+)\ *\}\}/g, function(_, $1) {
return locals[$1];
});
return attrs;
}, {}, template.attrs);
return foldl(
function(attrs, val, key) {
attrs[key] = val.replace(/\{\{\ *(\w+)\ *\}\}/g, function(_, $1) {
return locals[$1];
});
return attrs;
},
{},
template.attrs
);
}
24 changes: 20 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@
],
"main": "lib/index.js",
"scripts": {
"test": "make test"
"test": "make test",
"lint": "eslint \"./{lib,test}/**/*.js\"",
"format": "prettier-eslint --write --list-different \"./{lib,test}/**/*.{js,json,md}\"",
"precommit": "lint-staged"
},
"lint-staged": {
"linters": {
"*.{js,json,md}": [
"prettier-eslint --write",
"git add"
]
}
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -36,6 +47,7 @@
"component-emitter": "^1.2.0",
"debug": "^2.2.0",
"domify": "^1.4.0",
"eslint-plugin-react": "^7.9.1",
"extend": "3.0.1",
"is": "^3.1.0",
"load-iframe": "^1.0.0",
Expand All @@ -47,9 +59,11 @@
"@segment/eslint-config": "^3.1.1",
"browserify": "^13.0.0",
"browserify-istanbul": "^2.0.0",
"eslint": "^2.9.0",
"eslint-plugin-mocha": "^2.2.0",
"eslint-plugin-require-path-exists": "^1.1.5",
"eslint": "^4.19.1",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-mocha": "^5.0.0",
"eslint-plugin-require-path-exists": "^1.1.8",
"husky": "^0.14.3",
"istanbul": "^0.4.3",
"karma": "^1.1.0",
"karma-browserify": "^5.0.4",
Expand All @@ -60,8 +74,10 @@
"karma-phantomjs-launcher": "^1.0.0",
"karma-sauce-launcher": "^1.0.0",
"karma-spec-reporter": "0.0.26",
"lint-staged": "^7.2.0",
"mocha": "^2.2.5",
"phantomjs-prebuilt": "^2.1.7",
"prettier-eslint-cli": "^4.7.1",
"proclaim": "^3.4.1",
"segmentio-facade": "^3.0.2",
"sinon": "1.7.3",
Expand Down
2 changes: 1 addition & 1 deletion test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "@segment/eslint-config/mocha"
"extends": ["prettier", "@segment/eslint-config/mocha"]
}
Loading