Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
[fixed] minor syntax issues
Browse files Browse the repository at this point in the history
  • Loading branch information
thealjey committed Jan 29, 2017
1 parent 4721782 commit 8f1c984
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 97 deletions.
4 changes: 2 additions & 2 deletions docs/JSLint.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ <h1 class="page-title">JSLint.js</h1>
* });
*/
run(paths: Array&lt;string>, callback: LintCallback) {
const report = this.linter.executeOnFiles(paths),
const {results} = this.linter.executeOnFiles(paths),
errors = [];

forEach(report.results, ({messages, filePath: file}) => {
forEach(results, ({messages, filePath: file}) => {
forEach(messages, ({line, column, message, ruleId: rule}) => {
errors.push({file, line, column, message, rule});
});
Expand Down
26 changes: 12 additions & 14 deletions docs/jsx.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,24 +132,22 @@ <h1 class="page-title">jsx.js</h1>
* @param {Object} element - a Cheerio Element
* @return {Object} a plain object describing a React Element
*/
export function transformElement(element: Object): Object {
const {name, attribs, children} = element;

transformStyle(attribs);
rename(attribs, 'for', 'htmlFor');
rename(attribs, 'class', 'className');
if ('input' === name) {
rename(attribs, 'checked', 'defaultChecked');
rename(attribs, 'value', 'defaultValue');
export function transformElement({name: type, attribs: props, children: childElements}: Object): Object {
transformStyle(props);
rename(props, 'for', 'htmlFor');
rename(props, 'class', 'className');
if ('input' === type) {
rename(props, 'checked', 'defaultChecked');
rename(props, 'value', 'defaultValue');
}
let childElements = transformElements(children);
let children = transformElements(childElements);

if ('textarea' === name &amp;&amp; childElements.length) {
attribs.defaultValue = childElements[0];
childElements = [];
if ('textarea' === type &amp;&amp; children.length) {
props.defaultValue = children[0];
children = [];
}

return {type: name, props: attribs, children: childElements};
return {type, props, children};
}

/**
Expand Down
21 changes: 7 additions & 14 deletions docs/logger.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,9 @@ <h1 class="page-title">logger.js</h1>
* log('Colorful ', bold(red('R'), green('G'), blue('B')), ' logs are ', underline('very'), ' easy!');
*/
export function log(...messages: Array&lt;string | number | Message>) {
const msg = new Message({ansi: ['', ''], css: ''}).addMessages(messages);
const {message, styles} = new Message({ansi: ['', ''], css: ''}).addMessages(messages);

console.log(msg.message, ...msg.styles);
console.log(message, ...styles);
}

/**
Expand All @@ -362,9 +362,8 @@ <h1 class="page-title">logger.js</h1>
*
* logError(new Error('Some error message'));
*/
export function logError(error: Error) {
const {message, stack} = error,
lines = stack.split('\n'),
export function logError({message, stack}: Error) {
const lines = stack.split('\n'),
{length} = lines;

log(formatErrorMarker(), ': ', message);
Expand Down Expand Up @@ -405,9 +404,7 @@ <h1 class="page-title">logger.js</h1>
* });
*/
export function logPostCSSWarnings(warnings: PostCSSWarning[]) {
forEach(warnings, w => {
const {text, plugin, node, line, column} = w;

forEach(warnings, ({text, plugin, node, line, column}) => {
log(formatErrorMarker('Warning'), ': ', ...formatLine(`${text}(${plugin})`, node.source.input.file, line, column));
});
log('PostCSS warnings: ', warnings.length);
Expand All @@ -433,9 +430,7 @@ <h1 class="page-title">logger.js</h1>
* ...
* });
*/
export function logSASSError(error: NodeSassError) {
const {message, file, line, column} = error;

export function logSASSError({message, file, line, column}: NodeSassError) {
log(formatErrorMarker('SASS error'), ': ', ...formatLine(message, file, line, column));
}

Expand All @@ -455,9 +450,7 @@ <h1 class="page-title">logger.js</h1>
* logLintingErrors(errors);
*/
export function logLintingErrors(errors: LintError[], prefix: ?string = null) {
forEach(errors, e => {
const {message, rule, file, line, column} = e;

forEach(errors, ({message, rule, file, line, column}) => {
log(formatErrorMarker(), ': ', ...formatLine(`${message}${rule ? ` (${rule})` : ''}`, file, line, column));
});
log(prefix ? `${prefix} l` : 'L', 'inting errors: ', errors.length);
Expand Down
8 changes: 4 additions & 4 deletions docs/module-jsx.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ <h4 class="name" id=".arrayToJSX"><span class="type-signature">(static) </span>a

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="jsx.js.html">jsx.js</a>, <a href="jsx.js.html#line163">line 163</a>
<a href="jsx.js.html">jsx.js</a>, <a href="jsx.js.html#line161">line 161</a>
</li></ul></dd>


Expand Down Expand Up @@ -347,7 +347,7 @@ <h4 class="name" id=".flatten"><span class="type-signature">(static) </span>flat

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="jsx.js.html">jsx.js</a>, <a href="jsx.js.html#line130">line 130</a>
<a href="jsx.js.html">jsx.js</a>, <a href="jsx.js.html#line128">line 128</a>
</li></ul></dd>


Expand Down Expand Up @@ -526,7 +526,7 @@ <h4 class="name" id=".htmlToArray"><span class="type-signature">(static) </span>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="jsx.js.html">jsx.js</a>, <a href="jsx.js.html#line189">line 189</a>
<a href="jsx.js.html">jsx.js</a>, <a href="jsx.js.html#line187">line 187</a>
</li></ul></dd>


Expand Down Expand Up @@ -712,7 +712,7 @@ <h4 class="name" id=".htmlToJSX"><span class="type-signature">(static) </span>ht

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="jsx.js.html">jsx.js</a>, <a href="jsx.js.html#line211">line 211</a>
<a href="jsx.js.html">jsx.js</a>, <a href="jsx.js.html#line209">line 209</a>
</li></ul></dd>


Expand Down
6 changes: 3 additions & 3 deletions docs/module-logger.html
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ <h4 class="name" id=".logLintingErrors"><span class="type-signature">(static) </

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="logger.js.html">logger.js</a>, <a href="logger.js.html#line403">line 403</a>
<a href="logger.js.html">logger.js</a>, <a href="logger.js.html#line398">line 398</a>
</li></ul></dd>


Expand Down Expand Up @@ -1383,7 +1383,7 @@ <h4 class="name" id=".logPostCSSWarnings"><span class="type-signature">(static)

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="logger.js.html">logger.js</a>, <a href="logger.js.html#line346">line 346</a>
<a href="logger.js.html">logger.js</a>, <a href="logger.js.html#line345">line 345</a>
</li></ul></dd>


Expand Down Expand Up @@ -1534,7 +1534,7 @@ <h4 class="name" id=".logSASSError"><span class="type-signature">(static) </span

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="logger.js.html">logger.js</a>, <a href="logger.js.html#line377">line 377</a>
<a href="logger.js.html">logger.js</a>, <a href="logger.js.html#line374">line 374</a>
</li></ul></dd>


Expand Down
4 changes: 2 additions & 2 deletions lib/JSLint.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ class JSLint {
* @instance
*/
run(paths, callback) {
const report = this.linter.executeOnFiles(paths),
const { results } = this.linter.executeOnFiles(paths),
errors = [];

(0, _forEach2.default)(report.results, ({ messages, filePath: file }) => {
(0, _forEach2.default)(results, ({ messages, filePath: file }) => {
(0, _forEach2.default)(messages, ({ line, column, message, ruleId: rule }) => {
errors.push({ file, line, column, message, rule });
});
Expand Down
26 changes: 12 additions & 14 deletions lib/jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,24 +132,22 @@ function rename(object, fromKey, toKey) {
* @param {Object} element - a Cheerio Element
* @return {Object} a plain object describing a React Element
*/
function transformElement(element) {
const { name, attribs, children } = element;

transformStyle(attribs);
rename(attribs, 'for', 'htmlFor');
rename(attribs, 'class', 'className');
if ('input' === name) {
rename(attribs, 'checked', 'defaultChecked');
rename(attribs, 'value', 'defaultValue');
function transformElement({ name: type, attribs: props, children: childElements }) {
transformStyle(props);
rename(props, 'for', 'htmlFor');
rename(props, 'class', 'className');
if ('input' === type) {
rename(props, 'checked', 'defaultChecked');
rename(props, 'value', 'defaultValue');
}
let childElements = transformElements(children);
let children = transformElements(childElements);

if ('textarea' === name && childElements.length) {
attribs.defaultValue = childElements[0];
childElements = [];
if ('textarea' === type && children.length) {
props.defaultValue = children[0];
children = [];
}

return { type: name, props: attribs, children: childElements };
return { type, props, children };
}

/**
Expand Down
21 changes: 7 additions & 14 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ function formatErrorMarker(message = 'Error') {
* log('Colorful ', bold(red('R'), green('G'), blue('B')), ' logs are ', underline('very'), ' easy!');
*/
function log(...messages) {
const msg = new Message({ ansi: ['', ''], css: '' }).addMessages(messages);
const { message, styles } = new Message({ ansi: ['', ''], css: '' }).addMessages(messages);

console.log(msg.message, ...msg.styles);
console.log(message, ...styles);
}

/**
Expand All @@ -349,9 +349,8 @@ function log(...messages) {
*
* logError(new Error('Some error message'));
*/
function logError(error) {
const { message, stack } = error,
lines = stack.split('\n'),
function logError({ message, stack }) {
const lines = stack.split('\n'),
{ length } = lines;

log(formatErrorMarker(), ': ', message);
Expand Down Expand Up @@ -392,9 +391,7 @@ function logError(error) {
* });
*/
function logPostCSSWarnings(warnings) {
(0, _forEach2.default)(warnings, w => {
const { text, plugin, node, line, column } = w;

(0, _forEach2.default)(warnings, ({ text, plugin, node, line, column }) => {
log(formatErrorMarker('Warning'), ': ', ...formatLine(`${text}(${plugin})`, node.source.input.file, line, column));
});
log('PostCSS warnings: ', warnings.length);
Expand All @@ -420,9 +417,7 @@ function logPostCSSWarnings(warnings) {
* ...
* });
*/
function logSASSError(error) {
const { message, file, line, column } = error;

function logSASSError({ message, file, line, column }) {
log(formatErrorMarker('SASS error'), ': ', ...formatLine(message, file, line, column));
}

Expand All @@ -442,9 +437,7 @@ function logSASSError(error) {
* logLintingErrors(errors);
*/
function logLintingErrors(errors, prefix = null) {
(0, _forEach2.default)(errors, e => {
const { message, rule, file, line, column } = e;

(0, _forEach2.default)(errors, ({ message, rule, file, line, column }) => {
log(formatErrorMarker(), ': ', ...formatLine(`${message}${rule ? ` (${rule})` : ''}`, file, line, column));
});
log(prefix ? `${prefix} l` : 'L', 'inting errors: ', errors.length);
Expand Down
4 changes: 2 additions & 2 deletions src/JSLint.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ export class JSLint {
* });
*/
run(paths: Array<string>, callback: LintCallback) {
const report = this.linter.executeOnFiles(paths),
const {results} = this.linter.executeOnFiles(paths),
errors = [];

forEach(report.results, ({messages, filePath: file}) => {
forEach(results, ({messages, filePath: file}) => {
forEach(messages, ({line, column, message, ruleId: rule}) => {
errors.push({file, line, column, message, rule});
});
Expand Down
26 changes: 12 additions & 14 deletions src/jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,22 @@ export function rename(object: Object, fromKey: string, toKey: string) {
* @param {Object} element - a Cheerio Element
* @return {Object} a plain object describing a React Element
*/
export function transformElement(element: Object): Object {
const {name, attribs, children} = element;

transformStyle(attribs);
rename(attribs, 'for', 'htmlFor');
rename(attribs, 'class', 'className');
if ('input' === name) {
rename(attribs, 'checked', 'defaultChecked');
rename(attribs, 'value', 'defaultValue');
export function transformElement({name: type, attribs: props, children: childElements}: Object): Object {
transformStyle(props);
rename(props, 'for', 'htmlFor');
rename(props, 'class', 'className');
if ('input' === type) {
rename(props, 'checked', 'defaultChecked');
rename(props, 'value', 'defaultValue');
}
let childElements = transformElements(children);
let children = transformElements(childElements);

if ('textarea' === name && childElements.length) {
attribs.defaultValue = childElements[0];
childElements = [];
if ('textarea' === type && children.length) {
props.defaultValue = children[0];
children = [];
}

return {type: name, props: attribs, children: childElements};
return {type, props, children};
}

/**
Expand Down
21 changes: 7 additions & 14 deletions src/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ export function formatErrorMarker(message: string = 'Error') {
* log('Colorful ', bold(red('R'), green('G'), blue('B')), ' logs are ', underline('very'), ' easy!');
*/
export function log(...messages: Array<string | number | Message>) {
const msg = new Message({ansi: ['', ''], css: ''}).addMessages(messages);
const {message, styles} = new Message({ansi: ['', ''], css: ''}).addMessages(messages);

console.log(msg.message, ...msg.styles);
console.log(message, ...styles);
}

/**
Expand All @@ -323,9 +323,8 @@ export function log(...messages: Array<string | number | Message>) {
*
* logError(new Error('Some error message'));
*/
export function logError(error: Error) {
const {message, stack} = error,
lines = stack.split('\n'),
export function logError({message, stack}: Error) {
const lines = stack.split('\n'),
{length} = lines;

log(formatErrorMarker(), ': ', message);
Expand Down Expand Up @@ -366,9 +365,7 @@ export function logError(error: Error) {
* });
*/
export function logPostCSSWarnings(warnings: PostCSSWarning[]) {
forEach(warnings, w => {
const {text, plugin, node, line, column} = w;

forEach(warnings, ({text, plugin, node, line, column}) => {
log(formatErrorMarker('Warning'), ': ', ...formatLine(`${text}(${plugin})`, node.source.input.file, line, column));
});
log('PostCSS warnings: ', warnings.length);
Expand All @@ -394,9 +391,7 @@ export function logPostCSSWarnings(warnings: PostCSSWarning[]) {
* ...
* });
*/
export function logSASSError(error: NodeSassError) {
const {message, file, line, column} = error;

export function logSASSError({message, file, line, column}: NodeSassError) {
log(formatErrorMarker('SASS error'), ': ', ...formatLine(message, file, line, column));
}

Expand All @@ -416,9 +411,7 @@ export function logSASSError(error: NodeSassError) {
* logLintingErrors(errors);
*/
export function logLintingErrors(errors: LintError[], prefix: ?string = null) {
forEach(errors, e => {
const {message, rule, file, line, column} = e;

forEach(errors, ({message, rule, file, line, column}) => {
log(formatErrorMarker(), ': ', ...formatLine(`${message}${rule ? ` (${rule})` : ''}`, file, line, column));
});
log(prefix ? `${prefix} l` : 'L', 'inting errors: ', errors.length);
Expand Down

0 comments on commit 8f1c984

Please sign in to comment.