Skip to content

Commit

Permalink
build: update to prettier@2 (#1782)
Browse files Browse the repository at this point in the history
* build: update prettier

* chore: remove trailing comma config as it is now default

* chore: format all the things
  • Loading branch information
ekashida authored Apr 16, 2020
1 parent f25a298 commit 20275fc
Show file tree
Hide file tree
Showing 235 changed files with 853 additions and 850 deletions.
3 changes: 1 addition & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"printWidth": 100,
"tabWidth": 4,
"singleQuote": true,
"trailingComma": "es5"
"tabWidth": 4
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"lerna": "^3.20.2",
"lint-staged": "^10.1.3",
"mime-types": "^2.1.26",
"prettier": "^1.19.1",
"prettier": "^2.0.4",
"rollup": "^1.32.1",
"rollup-plugin-cleanup": "^3.1.1",
"rollup-plugin-compat": "^0.22.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function transform(plugin, pluginOpts = {}, opts = {}) {
opts
);

return function(source) {
return function (source) {
return babel.transform(prettify(source), testConfig);
};
}
Expand All @@ -30,15 +30,15 @@ function prettify(str) {
.toString()
.replace(/^\s+|\s+$/, '')
.split('\n')
.map(line => line.trim())
.filter(line => line.length)
.map((line) => line.trim())
.filter((line) => line.length)
.join('\n');
}

function pluginTest(plugin, pluginOpts, opts = {}) {
const testTransform = transform(plugin, pluginOpts, opts);

const transformTest = function(actual, expected) {
const transformTest = function (actual, expected) {
if (expected.error) {
let transformError;

Expand Down Expand Up @@ -72,7 +72,7 @@ function pluginTest(plugin, pluginOpts, opts = {}) {

const pluginTester = (name, actual, expected) =>
test(name, () => transformTest(actual, expected));
pluginTester.skip = name => test.skip(name);
pluginTester.skip = (name) => test.skip(name);
pluginTester.only = (name, actual, expected) => {
// eslint-disable-next-line jest/no-focused-tests
test.only(name, () => transformTest(actual, expected));
Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/babel-plugin-component/src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { generateError, getEngineImportSpecifiers } = require('./utils');
const { LWC_PACKAGE_EXPORTS, LWC_SUPPORTED_APIS } = require('./constants');
const { LWCClassErrors } = require('@lwc/errors');

module.exports = function() {
module.exports = function () {
return {
Program(path, state) {
const engineImportSpecifiers = getEngineImportSpecifiers(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function getSiblingGetSetPair(propertyPath, propertyName, type) {
const siblingType = type === 'getter' ? 'set' : 'get';
const klassBody = propertyPath.parentPath.get('body');
const siblingNode = klassBody.find(
classMethodPath =>
(classMethodPath) =>
classMethodPath !== propertyPath &&
classMethodPath.isClassMethod({ kind: siblingType }) &&
classMethodPath.node.key.name === propertyName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const { generateError } = require('../../utils');

function validateConflict(path, decorators) {
const isPublicFieldTracked = decorators.some(
decorator =>
(decorator) =>
decorator.name === TRACK_DECORATOR &&
decorator.path.parentPath.node === path.parentPath.node
);
Expand Down Expand Up @@ -84,7 +84,7 @@ function validateSingleApiDecoratorOnSetterGetterPair(decorators) {
// keep track of visited class methods
const visitedMethods = new Set();

decorators.forEach(decorator => {
decorators.forEach((decorator) => {
const { path, type } = decorator;

// since we are validating get/set we only look at @api methods
Expand Down
8 changes: 4 additions & 4 deletions packages/@lwc/babel-plugin-component/src/decorators/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const { DecoratorErrors } = require('@lwc/errors');
const DECORATOR_TRANSFORMS = [api, wire, track];

function isLwcDecoratorName(name) {
return DECORATOR_TRANSFORMS.some(transform => transform.name === name);
return DECORATOR_TRANSFORMS.some((transform) => transform.name === name);
}

/** Returns a list of all the references to an identifier */
Expand Down Expand Up @@ -52,7 +52,7 @@ function getLwcDecorators(importSpecifiers) {
.reduce((acc, { name, path }) => {
// Get a list of all the local references
const local = path.get('imported');
const references = getReferences(local).map(reference => ({
const references = getReferences(local).map((reference) => ({
name,
reference,
}));
Expand Down Expand Up @@ -94,7 +94,7 @@ function getLwcDecorators(importSpecifiers) {
/** Group decorator per class */
function groupDecorator(decorators) {
return decorators.reduce((acc, decorator) => {
const classPath = decorator.path.findParent(node => node.isClass());
const classPath = decorator.path.findParent((node) => node.isClass());

if (acc.has(classPath)) {
acc.set(classPath, [...acc.get(classPath), decorator]);
Expand Down Expand Up @@ -180,7 +180,7 @@ function decorators({ types: t }) {
},

Decorator(path) {
const AVAILABLE_DECORATORS = DECORATOR_TRANSFORMS.map(transform => transform.name);
const AVAILABLE_DECORATORS = DECORATOR_TRANSFORMS.map((transform) => transform.name);

throw generateError(path.parentPath, {
errorInfo: DecoratorErrors.INVALID_DECORATOR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ function isObservedProperty(configProperty) {
function getWiredStatic(wireConfig) {
return wireConfig
.get('properties')
.filter(property => !isObservedProperty(property))
.map(path => path.node);
.filter((property) => !isObservedProperty(property))
.map((path) => path.node);
}

function getWiredParams(t, wireConfig) {
return wireConfig
.get('properties')
.filter(property => isObservedProperty(property))
.map(path => {
.filter((property) => isObservedProperty(property))
.map((path) => {
// Need to clone deep the observed property to remove the param prefix
const clonedProperty = t.cloneDeep(path.node);
clonedProperty.value.value = clonedProperty.value.value.slice(1);
Expand All @@ -42,15 +42,15 @@ function getGeneratedConfig(t, wiredValue) {
let counter = 0;
const configBlockBody = [];
const configProps = [];
const generateParameterConfigValue = memberExprPaths => {
const generateParameterConfigValue = (memberExprPaths) => {
// Note: When memberExprPaths ($foo.bar) has an invalid identifier (eg: foo..bar, foo.bar[3])
// it should (ideally) resolve in a compilation error during validation phase.
// This is not possible due that platform components may have a param definition which is invalid
// but passes compilation, and throwing at compile time would break such components.
// In such cases where the param does not have proper notation, the config generated will use the bracket
// notation to match the current behavior (that most likely end up resolving that param as undefined).
const isInvalidMemberExpr = memberExprPaths.some(
maybeIdentifier =>
(maybeIdentifier) =>
!(t.isValidES3Identifier(maybeIdentifier) && maybeIdentifier.length > 0)
);
const memberExprPropertyGen = !isInvalidMemberExpr ? t.identifier : t.StringLiteral;
Expand Down Expand Up @@ -119,7 +119,7 @@ function getGeneratedConfig(t, wiredValue) {
}

if (wiredValue.params) {
wiredValue.params.forEach(param => {
wiredValue.params.forEach((param) => {
const memberExprPaths = param.value.value.split('.');
const paramConfigValue = generateParameterConfigValue(memberExprPaths);

Expand All @@ -144,7 +144,7 @@ function getGeneratedConfig(t, wiredValue) {

function buildWireConfigValue(t, wiredValues) {
return t.objectExpression(
wiredValues.map(wiredValue => {
wiredValues.map((wiredValue) => {
const wireConfig = [];
if (wiredValue.adapter) {
wireConfig.push(
Expand Down Expand Up @@ -190,7 +190,7 @@ const SUPPORTED_VALUE_TO_TYPE_MAP = {
BooleanLiteral: 'boolean',
};

const scopedReferenceLookup = scope => name => {
const scopedReferenceLookup = (scope) => (name) => {
const binding = scope.getBinding(name);

let type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function validateWireParameters(path) {
}

function validateUsageWithOtherDecorators(path, decorators) {
decorators.forEach(decorator => {
decorators.forEach((decorator) => {
if (
path !== decorator.path &&
decorator.name === WIRE_DECORATOR &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function validateImport(sourcePath) {
* Expected API for this plugin:
* { dynamicImports: { loader: string, strictSpecifier: boolean } }
*/
module.exports = function() {
module.exports = function () {
function getLoaderRef(path, loaderName, state) {
if (!state.loaderRef) {
state.loaderRef = moduleImports.addNamed(path, 'load', loaderName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ module.exports = function postProcess({ types: t }) {
const nonDecoratedFields = body
.get('body')
.filter(
path =>
(path) =>
t.isClassProperty(path.node) &&
!isLWCNode(path.node) &&
!path.node.static &&
t.isIdentifier(path.node.key) &&
!(decoratedIdentifiers.indexOf(path.node.key.name) >= 0)
)
.map(path => path.node.key.name);
.map((path) => path.node.key.name);

return nonDecoratedFields.length
? t.objectProperty(t.identifier('fields'), t.valueToNode(nonDecoratedFields))
Expand Down
4 changes: 2 additions & 2 deletions packages/@lwc/babel-plugin-component/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ function staticClassProperty(types, name, expression) {
}

function getEngineImportsStatements(path) {
const programPath = path.isProgram() ? path : path.findParent(node => node.isProgram());
const programPath = path.isProgram() ? path : path.findParent((node) => node.isProgram());

return programPath.get('body').filter(node => {
return programPath.get('body').filter((node) => {
const source = node.get('source');
return node.isImportDeclaration() && source.isStringLiteral({ value: LWC_PACKAGE_ALIAS });
});
Expand Down
4 changes: 2 additions & 2 deletions packages/@lwc/compiler/src/__tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function pretify(str: string): string {
.toString()
.replace(/^\s+|\s+$/, '')
.split('\n')
.map(line => line.trim())
.filter(line => line.length)
.map((line) => line.trim())
.filter((line) => line.length)
.join('\n');
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function getConfig(env = {}) {
};
}

describe('environment replacement', function() {
describe('environment replacement', function () {
it('should not replace environment variable if unset', async () => {
const {
result: { code },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export default class Test extends LightningElement {
},
});

await SourceMapConsumer.with(result!.map, null, sourceMapConsumer => {
await SourceMapConsumer.with(result!.map, null, (sourceMapConsumer) => {
const mainDefMappedToOutputPosition = sourceMapConsumer.generatedPositionFor({
source: 'utils/util.js',
line: 1,
Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/compiler/src/compiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function compile(options: CompileOptions): Promise<CompilerOutput>
}

function hasError(diagnostics: CompilerDiagnostic[]) {
return diagnostics.some(d => {
return diagnostics.some((d) => {
return d.level === DiagnosticLevel.Error || d.level === DiagnosticLevel.Fatal;
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('rollup plugin lwc-compat', () => {

expect(result.map).not.toBeNull();

await SourceMapConsumer.with(result!.map, null, sourceMapConsumer => {
await SourceMapConsumer.with(result!.map, null, (sourceMapConsumer) => {
const varMappedToConstPosition = sourceMapConsumer.originalPositionFor({
line: 2,
column: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('rollup plugin lwc-minify', () => {

expect(result.map).not.toBeNull();

await SourceMapConsumer.with(result!.map, null, sourceMapConsumer => {
await SourceMapConsumer.with(result!.map, null, (sourceMapConsumer) => {
const commentInOutputPosition = sourceMapConsumer.generatedPositionFor({
line: 2,
column: 0,
Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/compiler/src/rollup-plugins/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as babel from '@babel/core';
import { BABEL_CONFIG_BASE } from '../babel-plugins';
import { NormalizedOutputConfig } from '../options';

export default function({ sourcemap }: NormalizedOutputConfig): Plugin {
export default function ({ sourcemap }: NormalizedOutputConfig): Plugin {
// Inlining the `babel-preset-compat` module require to only pay the parsing and evaluation cost for needed modules
const presetCompat = require('babel-preset-compat');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import rollupPluginReplace from '@rollup/plugin-replace';

import { NormalizedCompileOptions } from '../options';

export default function({ options }: { options: NormalizedCompileOptions }): Plugin {
export default function ({ options }: { options: NormalizedCompileOptions }): Plugin {
const { env } = options.outputConfig;

const patterns: { [pattern: string]: string } = {};
Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/compiler/src/rollup-plugins/minify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { NormalizedOutputConfig } from '../options';
/**
* Rollup plugin applying minification to the generated bundle.
*/
export default function({ sourcemap }: NormalizedOutputConfig): Plugin {
export default function ({ sourcemap }: NormalizedOutputConfig): Plugin {
// Inlining the `terser` module require to only pay the parsing and evaluation cost for needed
// modules
const { minify } = require('terser');
Expand Down
5 changes: 3 additions & 2 deletions packages/@lwc/compiler/src/rollup-plugins/module-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ function isFirstCharacterUppercased(importee: string) {

function inferExtension(fileName: string, files: BundleFiles) {
if (!path.extname(fileName)) {
const ext = VALID_EXTENSIONS.find(ext => hasOwnProperty.call(files, fileName + ext)) || '';
const ext =
VALID_EXTENSIONS.find((ext) => hasOwnProperty.call(files, fileName + ext)) || '';
return fileName + ext;
}
return fileName;
Expand Down Expand Up @@ -131,7 +132,7 @@ function getCaseIgnoredFilenameMatch(files: { [key: string]: string }, nameToMat
);
}

export default function({ options }: { options: NormalizedCompileOptions }): Plugin {
export default function ({ options }: { options: NormalizedCompileOptions }): Plugin {
return {
name: 'lwc-module-resolver',

Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/compiler/src/rollup-plugins/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { transformFile } from '../transformers/transformer';

import { NormalizedCompileOptions } from '../options';

export default function({ options }: { options: NormalizedCompileOptions }): Plugin {
export default function ({ options }: { options: NormalizedCompileOptions }): Plugin {
return {
name: 'lwc-file-transform',
transform(src: string, id: string) {
Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/compiler/src/transformers/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function templateTransform(
throw normalizeToCompilerError(TransformerErrors.HTML_TRANSFORMER_ERROR, e, { filename });
}

const fatalError = result.warnings.find(warning => warning.level === DiagnosticLevel.Error);
const fatalError = result.warnings.find((warning) => warning.level === DiagnosticLevel.Error);
if (fatalError) {
throw CompilerError.from(fatalError, { filename });
}
Expand Down
4 changes: 2 additions & 2 deletions packages/@lwc/engine/scripts/jest/matchers/log-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function createMatcher(methodName) {
if (this.isNot) {
if (receivedMessages.length > 0) {
const formattedMessages = receivedMessages
.map(message => this.utils.printReceived(message))
.map((message) => this.utils.printReceived(message))
.join('\n\n');

return {
Expand Down Expand Up @@ -80,7 +80,7 @@ function createMatcher(methodName) {
}
} else {
const formattedMessages = receivedMessages
.map(message => this.utils.printReceived(message))
.map((message) => this.utils.printReceived(message))
.join('\n\n');

return {
Expand Down
Loading

0 comments on commit 20275fc

Please sign in to comment.