Skip to content

Commit

Permalink
[Refactor] extract getTokenBeforeClosingBracket to a file.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Nov 7, 2016
1 parent 56846a6 commit fd51133
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 29 deletions.
15 changes: 2 additions & 13 deletions lib/rules/jsx-space-before-closing.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
'use strict';

var getTokenBeforeClosingBracket = require('../util/getTokenBeforeClosingBracket');

// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
Expand All @@ -30,19 +32,6 @@ module.exports = {
var NEVER_MESSAGE = 'A space is forbidden before closing bracket';
var ALWAYS_MESSAGE = 'A space is required before closing bracket';

/**
* Find the token before the closing bracket.
* @param {ASTNode} node - The JSX element node.
* @returns {Token} The token before the closing bracket.
*/
function getTokenBeforeClosingBracket(node) {
var attributes = node.attributes;
if (attributes.length === 0) {
return node.name;
}
return attributes[ attributes.length - 1 ];
}

// --------------------------------------------------------------------------
// Public
// --------------------------------------------------------------------------
Expand Down
17 changes: 1 addition & 16 deletions lib/rules/jsx-tag-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,7 @@
*/
'use strict';

// ------------------------------------------------------------------------------
// Helpers
// ------------------------------------------------------------------------------

/**
* Find the token before the closing bracket.
* @param {ASTNode} node - The JSX element node.
* @returns {Token} The token before the closing bracket.
*/
function getTokenBeforeClosingBracket(node) {
var attributes = node.attributes;
if (attributes.length === 0) {
return node.name;
}
return attributes[ attributes.length - 1 ];
}
var getTokenBeforeClosingBracket = require('../util/getTokenBeforeClosingBracket');

// ------------------------------------------------------------------------------
// Validators
Expand Down
16 changes: 16 additions & 0 deletions lib/util/getTokenBeforeClosingBracket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

/**
* Find the token before the closing bracket.
* @param {ASTNode} node - The JSX element node.
* @returns {Token} The token before the closing bracket.
*/
function getTokenBeforeClosingBracket(node) {
var attributes = node.attributes;
if (attributes.length === 0) {
return node.name;
}
return attributes[attributes.length - 1];
}

module.exports = getTokenBeforeClosingBracket;

0 comments on commit fd51133

Please sign in to comment.