Skip to content

Commit

Permalink
Update to prettier 2 and reformat all files
Browse files Browse the repository at this point in the history
  • Loading branch information
Munter committed May 24, 2020
1 parent d10b5cb commit de6a482
Show file tree
Hide file tree
Showing 27 changed files with 1,535 additions and 1,520 deletions.
12 changes: 6 additions & 6 deletions lib/HeadlessBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function downloadOrLocatePreferredBrowserRevision() {
revisionInfo = await browserFetcher.download(preferredRevision);
}
return puppeteer.launch({
executablePath: revisionInfo.executablePath
executablePath: revisionInfo.executablePath,
});
}

Expand Down Expand Up @@ -58,7 +58,7 @@ class HeadlessBrowser {
// fake a response from the assetgraph instance if the corresponding
// asset is found there:
await page.setRequestInterception(true);
page.on('request', request => {
page.on('request', (request) => {
const url = request.url();
if (url.startsWith(baseUrl)) {
let agUrl = url.replace(baseUrl, assetGraph.root);
Expand All @@ -67,13 +67,13 @@ class HeadlessBrowser {
}
const asset = assetGraph.findAssets({
isLoaded: true,
url: agUrl
url: agUrl,
})[0];
if (asset) {
request.respond({
status: 200,
contentType: asset.contentType,
body: asset.rawSrc
body: asset.rawSrc,
});
return;
}
Expand All @@ -82,7 +82,7 @@ class HeadlessBrowser {
request.continue();
});

page.on('requestfailed', request => {
page.on('requestfailed', (request) => {
const response = request.response();
if (response && response.status() > 400) {
this.console.error(
Expand Down Expand Up @@ -111,7 +111,7 @@ class HeadlessBrowser {
);

await page.addScriptTag({
path: require.resolve('font-tracer/dist/fontTracer.browser.js')
path: require.resolve('font-tracer/dist/fontTracer.browser.js'),
});

const jsHandle = await page.evaluateHandle(
Expand Down
2 changes: 1 addition & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ require('@gustavnikolaj/async-main-wrap')(require('./subfont'), {
err.customOutput = err.message;
}
return err;
}
},
})(options, console);
8 changes: 4 additions & 4 deletions lib/downloadGoogleFonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const formatAgents = {
woff:
'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; rv:11.0) like Gecko',
woff2:
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; ServiceUI 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393'
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; ServiceUI 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393',
};

/**
Expand Down Expand Up @@ -61,7 +61,7 @@ async function downloadGoogleFonts(
}

result.src = await Promise.all(
sortedFormats.map(async format => {
sortedFormats.map(async (format) => {
const assetGraph = new AssetGraph();
assetGraph.teepee.headers['User-Agent'] = formatAgents[format];

Expand All @@ -71,10 +71,10 @@ async function downloadGoogleFonts(

const [fontRelation] = assetGraph.findRelations({
from: cssAsset,
type: 'CssFontFaceSrc'
type: 'CssFontFaceSrc',
});

fontRelation.node.each(decl => {
fontRelation.node.each((decl) => {
if (decl.prop !== 'src') {
result[decl.prop] = decl.value;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/findCustomPropertyDefinitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function findCustomPropertyDefinitions(cssAssets) {
const definitionsByProp = {};
const incomingReferencesByProp = {};
for (const cssAsset of cssAssets) {
cssAsset.eachRuleInParseTree(cssRule => {
cssAsset.eachRuleInParseTree((cssRule) => {
if (
cssRule.parent.type === 'rule' &&
cssRule.type === 'decl' &&
Expand Down
8 changes: 4 additions & 4 deletions lib/gatherStylesheetsWithPredicates.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ module.exports = function gatherStylesheetsWithPredicates(
'HtmlStyle',
'CssImport',
'HtmlConditionalComment',
'HtmlNoscript'
]
}
'HtmlNoscript',
],
},
})) {
if (relation.type === 'HtmlNoscript') {
traverse(relation.to, isWithinNotIeConditionalComment, true);
Expand Down Expand Up @@ -71,7 +71,7 @@ module.exports = function gatherStylesheetsWithPredicates(
}
result.push({
text: asset.text,
predicates
predicates,
});
}
})(htmlAsset);
Expand Down
34 changes: 17 additions & 17 deletions lib/getCssRulesByProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const counterRendererNames = new Set([
'upper-alpha',
'armenian',
'georgian',
'hebrew'
'hebrew',
]);

function unwrapNamespace(str) {
Expand All @@ -42,7 +42,7 @@ function getCssRulesByProperty(properties, cssSource, existingPredicates) {

const parseTree = postcss.parse(cssSource);
let defaultNamespaceURI = 'http://www.w3.org/1999/xhtml';
parseTree.walkAtRules('namespace', rule => {
parseTree.walkAtRules('namespace', (rule) => {
const fragments = rule.params.split(/\s+/);
if (fragments.length === 1) {
defaultNamespaceURI = unwrapNamespace(rule.params);
Expand All @@ -52,7 +52,7 @@ function getCssRulesByProperty(properties, cssSource, existingPredicates) {
});
const rulesByProperty = {
counterStyles: [],
keyframes: []
keyframes: [],
};

for (const property of properties) {
Expand Down Expand Up @@ -81,7 +81,7 @@ function getCssRulesByProperty(properties, cssSource, existingPredicates) {
// Split up combined selectors as they might have different specificity
specificity
.calculate(node.parent.selector)
.forEach(specificityObject => {
.forEach((specificityObject) => {
const isStyleAttribute =
specificityObject.selector === 'bogusselector';
(rulesByProperty[propName] = rulesByProperty[propName] || []).push({
Expand All @@ -95,7 +95,7 @@ function getCssRulesByProperty(properties, cssSource, existingPredicates) {
: specificityObject.specificityArray,
prop: propName,
value: node.value,
important: !!node.important
important: !!node.important,
});
});
} else if (
Expand Down Expand Up @@ -125,7 +125,7 @@ function getCssRulesByProperty(properties, cssSource, existingPredicates) {
// Split up combined selectors as they might have different specificity
specificity
.calculate(node.parent.selector)
.forEach(specificityObject => {
.forEach((specificityObject) => {
const isStyleAttribute =
specificityObject.selector === 'bogusselector';

Expand All @@ -140,7 +140,7 @@ function getCssRulesByProperty(properties, cssSource, existingPredicates) {
: specificityObject.specificityArray,
prop: 'list-style-type',
value: listStyleType,
important: !!node.important
important: !!node.important,
});
});
}
Expand All @@ -154,7 +154,7 @@ function getCssRulesByProperty(properties, cssSource, existingPredicates) {
// Split up combined selectors as they might have different specificity
specificity
.calculate(node.parent.selector)
.forEach(specificityObject => {
.forEach((specificityObject) => {
const isStyleAttribute =
specificityObject.selector === 'bogusselector';

Expand All @@ -169,7 +169,7 @@ function getCssRulesByProperty(properties, cssSource, existingPredicates) {
: specificityObject.specificityArray,
prop: 'animation-name',
value: animationName,
important: !!node.important
important: !!node.important,
});
});
} else if (propName === 'transition') {
Expand All @@ -189,7 +189,7 @@ function getCssRulesByProperty(properties, cssSource, existingPredicates) {
// Split up combined selectors as they might have different specificity
specificity
.calculate(node.parent.selector)
.forEach(specificityObject => {
.forEach((specificityObject) => {
const isStyleAttribute =
specificityObject.selector === 'bogusselector';
if (properties.includes('transition-property')) {
Expand All @@ -204,7 +204,7 @@ function getCssRulesByProperty(properties, cssSource, existingPredicates) {
: specificityObject.specificityArray,
prop: 'transition-property',
value: transitionProperties.join(', '),
important: !!node.important
important: !!node.important,
});
}
if (properties.includes('transition-duration')) {
Expand All @@ -219,14 +219,14 @@ function getCssRulesByProperty(properties, cssSource, existingPredicates) {
: specificityObject.specificityArray,
prop: 'transition-duration',
value: transitionDurations.join(', '),
important: !!node.important
important: !!node.important,
});
}
});
} else if (propName === 'font') {
specificity
.calculate(node.parent.selector)
.forEach(specificityObject => {
.forEach((specificityObject) => {
const isStyleAttribute =
specificityObject.selector === 'bogusselector';
const value = {
Expand All @@ -240,14 +240,14 @@ function getCssRulesByProperty(properties, cssSource, existingPredicates) {
: specificityObject.specificityArray,
prop: 'font',
value: node.value,
important: !!node.important
important: !!node.important,
};

for (const prop of [
'font-family',
'font-weight',
'font-size',
'font-style'
'font-style',
]) {
if (properties.includes(prop)) {
rulesByProperty[prop].push(value);
Expand All @@ -266,7 +266,7 @@ function getCssRulesByProperty(properties, cssSource, existingPredicates) {
rulesByProperty.counterStyles.push({
name: node.params,
predicates: getCurrentPredicates(),
props
props,
});
} else if (
node.type === 'atrule' &&
Expand All @@ -276,7 +276,7 @@ function getCssRulesByProperty(properties, cssSource, existingPredicates) {
name: node.params,
namespaceURI: defaultNamespaceURI,
predicates: getCurrentPredicates(),
node
node,
});
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/initialValueByProp.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ module.exports = {
'counter-increment': 'none',
'counter-reset': 'none',
'counter-set': 'none',
'white-space': 'normal'
'white-space': 'normal',
};
6 changes: 3 additions & 3 deletions lib/injectSubsetDefinitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const postcssValueParser = require('postcss-value-parser');

function injectSubsetDefinitions(cssValue, webfontNameMap, replaceOriginal) {
const subsetFontNames = new Set(
Object.values(webfontNameMap).map(name => name.toLowerCase())
Object.values(webfontNameMap).map((name) => name.toLowerCase())
);
const rootNode = postcssValueParser(cssValue);
let isPreceededByWords = false;
Expand Down Expand Up @@ -40,7 +40,7 @@ function injectSubsetDefinitions(cssValue, webfontNameMap, replaceOriginal) {
/'/g,
"\\'"
),
quote: "'"
quote: "'",
};
if (replaceOriginal) {
rootNode.nodes.splice(
Expand All @@ -52,7 +52,7 @@ function injectSubsetDefinitions(cssValue, webfontNameMap, replaceOriginal) {
rootNode.nodes.splice(rootNode.nodes.indexOf(node), 0, newToken, {
type: 'div',
value: ',',
after: ' '
after: ' ',
});
}
return postcssValueParser.stringify(rootNode);
Expand Down
Loading

0 comments on commit de6a482

Please sign in to comment.