Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Linting fixes after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
eliperelman committed May 15, 2018
1 parent d27c4d9 commit 8e527a0
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 153 deletions.
79 changes: 41 additions & 38 deletions src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,53 +82,56 @@ module.exports = class extends ChainedMap {
);
}

toString({
verbose = false,
configPrefix = 'config'
} = {}) {
toString({ verbose = false, configPrefix = 'config' } = {}) {
// eslint-disable-next-line global-require
const stringify = require('javascript-stringify');

const config = this.toConfig();

return stringify(config, (value, indent, stringify) => {
// improve plugin output
if (value && value.__pluginName) {
const prefix = `/* ${configPrefix}.plugin('${value.__pluginName}') */\n`;
const constructorName = value.__pluginConstructorName;

if (constructorName) {
// get correct indentation for args by stringifying the args array and
// discarding the square brackets.
const args = stringify(value.__pluginArgs).slice(1, -1);
return prefix + `new ${constructorName}(${args})`;
} else {
return stringify(
config,
(value, indent, stringify) => {
// improve plugin output
if (value && value.__pluginName) {
const prefix = `/* ${configPrefix}.plugin('${
value.__pluginName
}') */\n`;
const constructorName = value.__pluginConstructorName;

if (constructorName) {
// get correct indentation for args by stringifying the args array and
// discarding the square brackets.
const args = stringify(value.__pluginArgs).slice(1, -1);
return `${prefix}new ${constructorName}(${args})`;
}
return prefix + stringify({ args: value.__pluginArgs || [] });
}
}

// improve rule/use output
if (value && value.__ruleNames) {
const prefix = `/* ${configPrefix}.module.rule('${
value.__ruleNames[0]
}')${
value.__ruleNames.slice(1).map(r => `.oneOf('${r}')`).join('')
}${
value.__useName ? `.use('${value.__useName}')` : ``
} */\n`;
return prefix + stringify(value);
}
// improve rule/use output
if (value && value.__ruleNames) {
const prefix = `/* ${configPrefix}.module.rule('${
value.__ruleNames[0]
}')${value.__ruleNames
.slice(1)
.map(r => `.oneOf('${r}')`)
.join('')}${
value.__useName ? `.use('${value.__useName}')` : ``
} */\n`;
return prefix + stringify(value);
}

// shorten long functions
if (typeof value === 'function') {
if (value.__expression) {
return value.__expression;
} else if (!verbose && value.toString().length > 100) {
return `function () { /* omitted long function */ }`;
// shorten long functions
if (typeof value === 'function') {
if (value.__expression) {
return value.__expression;
} else if (!verbose && value.toString().length > 100) {
return `function () { /* omitted long function */ }`;
}
}
}

return stringify(value);
}, 2);
return stringify(value);
},
2
);
}

merge(obj = {}, omit = []) {
Expand Down
78 changes: 39 additions & 39 deletions src/Plugin.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
const ChainedMap = require('./ChainedMap');
const Orderable = require('./Orderable');

module.exports = Orderable(class extends ChainedMap {
constructor(parent, name) {
super(parent);
this.name = name;
this.extend(['init']);
module.exports = Orderable(
class extends ChainedMap {
constructor(parent, name) {
super(parent);
this.name = name;
this.extend(['init']);

this.init((Plugin, args = []) => new Plugin(...args));
}

this.init((Plugin, args = []) => new Plugin(...args));
}
use(plugin, args = []) {
return this.set('plugin', plugin).set('args', args);
}

use(plugin, args = []) {
return this
.set('plugin', plugin)
.set('args', args);
}
tap(f) {
this.set('args', f(this.get('args') || []));
return this;
}

tap(f) {
this.set('args', f(this.get('args') || []));
return this;
}
merge(obj, omit = []) {
if ('plugin' in obj) {
this.set('plugin', obj.plugin);
}

merge(obj, omit = []) {
if ('plugin' in obj) {
this.set('plugin', obj.plugin);
}
if ('args' in obj) {
this.set('args', obj.args);
}

if ('args' in obj) {
this.set('args', obj.args);
return super.merge(obj, [...omit, 'args', 'plugin']);
}

return super.merge(obj, [...omit, 'args', 'plugin']);
}
toConfig() {
const init = this.get('init');
const plugin = this.get('plugin');
const constructorName = plugin.__expression
? `(${plugin.__expression})`
: plugin.name;

toConfig() {
const init = this.get('init');
const plugin = this.get('plugin');
const constructorName = plugin.__expression
? `(${plugin.__expression})`
: plugin.name;
const config = init(this.get('plugin'), this.get('args'));

const config = init(this.get('plugin'), this.get('args'));
Object.defineProperties(config, {
__pluginName: { value: this.name },
__pluginArgs: { value: this.get('args') },
__pluginConstructorName: { value: constructorName },
});

Object.defineProperties(config, {
__pluginName: { value: this.name },
__pluginArgs: { value: this.get('args') },
__pluginConstructorName: { value: constructorName }
});

return config;
return config;
}
}
});
);
37 changes: 22 additions & 15 deletions src/Rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = class Rule extends ChainedMap {
'resourceQuery',
'sideEffects',
'test',
'type'
'type',
]);
}

Expand Down Expand Up @@ -55,15 +55,17 @@ module.exports = class Rule extends ChainedMap {
}

toConfig() {
const config = this.clean(Object.assign(this.entries() || {}, {
include: this.include.values(),
exclude: this.exclude.values(),
oneOf: this.oneOfs.values().map(oneOf => oneOf.toConfig()),
use: this.uses.values().map(use => use.toConfig())
}));
const config = this.clean(
Object.assign(this.entries() || {}, {
include: this.include.values(),
exclude: this.exclude.values(),
oneOf: this.oneOfs.values().map(oneOf => oneOf.toConfig()),
use: this.uses.values().map(use => use.toConfig()),
})
);

Object.defineProperties(config, {
__ruleNames: { value: this.names }
__ruleNames: { value: this.names },
});

return config;
Expand All @@ -79,21 +81,26 @@ module.exports = class Rule extends ChainedMap {
}

if (!omit.includes('use') && 'use' in obj) {
Object
.keys(obj.use)
.forEach(name => this.use(name).merge(obj.use[name]));
Object.keys(obj.use).forEach(name => this.use(name).merge(obj.use[name]));
}

if (!omit.includes('oneOf') && 'oneOf' in obj) {
Object
.keys(obj.oneOf)
.forEach(name => this.oneOf(name).merge(obj.oneOf[name]));
Object.keys(obj.oneOf).forEach(name =>
this.oneOf(name).merge(obj.oneOf[name])
);
}

if (!omit.includes('test') && 'test' in obj) {
this.test(obj.test instanceof RegExp ? obj.test : new RegExp(obj.test));
}

return super.merge(obj, [...omit, 'include', 'exclude', 'use', 'oneOf', 'test']);
return super.merge(obj, [
...omit,
'include',
'exclude',
'use',
'oneOf',
'test',
]);
}
};
56 changes: 29 additions & 27 deletions src/Use.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,40 @@ const ChainedMap = require('./ChainedMap');
const Orderable = require('./Orderable');
const merge = require('deepmerge');

module.exports = Orderable(class extends ChainedMap {
constructor(parent, name) {
super(parent);
this.name = name;
this.extend(['loader', 'options']);
}

tap(f) {
this.options(f(this.get('options')));
return this;
}

merge(obj, omit = []) {
if (!omit.includes('loader') && 'loader' in obj) {
this.loader(obj.loader);
module.exports = Orderable(
class extends ChainedMap {
constructor(parent, name) {
super(parent);
this.name = name;
this.extend(['loader', 'options']);
}

if (!omit.includes('options') && 'options' in obj) {
this.options(merge(this.store.get('options') || {}, obj.options));
tap(f) {
this.options(f(this.get('options')));
return this;
}

return super.merge(obj, [...omit, 'loader', 'options']);
}
merge(obj, omit = []) {
if (!omit.includes('loader') && 'loader' in obj) {
this.loader(obj.loader);
}

toConfig() {
const config = this.clean(this.entries() || {});
if (!omit.includes('options') && 'options' in obj) {
this.options(merge(this.store.get('options') || {}, obj.options));
}

Object.defineProperties(config, {
__useName: { value: this.name },
__ruleNames: { value: this.parent && this.parent.names }
});
return super.merge(obj, [...omit, 'loader', 'options']);
}

toConfig() {
const config = this.clean(this.entries() || {});

return config;
Object.defineProperties(config, {
__useName: { value: this.name },
__ruleNames: { value: this.parent && this.parent.names },
});

return config;
}
}
});
);
Loading

0 comments on commit 8e527a0

Please sign in to comment.