Skip to content

Commit

Permalink
eslint: use object-curly-spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
duaraghav8 committed Jan 28, 2019
1 parent 0aae30c commit 3b95a04
Show file tree
Hide file tree
Showing 25 changed files with 189 additions and 184 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ module.exports = {
"error",
"never"
],
"object-curly-spacing": [
"error",
"always"
],
"comma-dangle": "error",
"comma-spacing": "error",
"strict": "error",
Expand Down
18 changes: 9 additions & 9 deletions lib/autofix/rule-fixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function validateArgs(args) {


function insertTextAt(index, text) {
validateArgs({index, text});
validateArgs({ index, text });

return {
range: [index, index],
Expand All @@ -66,12 +66,12 @@ let ruleFixerAPI = {
insertTextAt,

insertTextAfter(node, text) {
validateArgs({node: node, text: text});
validateArgs({ node: node, text: text });
return this.insertTextAfterRange([node.start, node.end], text);
},

insertTextBefore(node, text) {
validateArgs({node: node, text: text});
validateArgs({ node: node, text: text });
return this.insertTextBeforeRange([node.start, node.end], text);
},

Expand All @@ -80,32 +80,32 @@ let ruleFixerAPI = {
},

replaceText(node, text) {
validateArgs({node: node, text: text});
validateArgs({ node: node, text: text });
return this.replaceTextRange([node.start, node.end], text);
},

insertTextAfterRange(range, text) {
validateArgs({range: range, text: text});
validateArgs({ range: range, text: text });
return insertTextAt(range [1], text);
},

insertTextBeforeRange(range, text) {
validateArgs({range: range, text: text});
validateArgs({ range: range, text: text });
return insertTextAt(range [0], text);
},

removeRange(range) {
validateArgs({range: range});
validateArgs({ range: range });
return this.replaceTextRange(range, "");
},

replaceChar(index, newChar) {
validateArgs({index: index, char: newChar});
validateArgs({ index: index, char: newChar });
return this.replaceTextRange([index, index + 1], newChar);
},

replaceTextRange(range, text) {
validateArgs({range: range, text: text});
validateArgs({ range: range, text: text });
return {
range: range,
text: text
Expand Down
4 changes: 2 additions & 2 deletions lib/reporters/pretty.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"use strict";

const path = require("path"), jsdiff = require("diff"),
sort = require("lodash/sortBy"), Table = require("text-table"), {EOL} = require("os");
sort = require("lodash/sortBy"), Table = require("text-table"), { EOL } = require("os");
require("colors");

let counts = {};
Expand Down Expand Up @@ -49,7 +49,7 @@ module.exports = {
return;
}

const {message, type} = issue;
const { message, type } = issue;
process.stdout.write(`${message[colorInternalIssue(type)]}${EOL}`);

delete lintErrors[index];
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/blank-lines.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ module.exports = {
});
}

const {node} = emitted, programBody = node.body;
const { node } = emitted, programBody = node.body;

for (let i = 1; i < programBody.length; i++) {
const currNode = programBody [i], prevNode = programBody [i-1];
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
return;
}

const {node} = emitted, {body} = node;
const { node } = emitted, { body } = node;

body.filter(child => {
return child.type === "FunctionDeclaration";
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/emit.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function create(context) {

// Determines whether the given call name refers to an event declaration using scope resolution.
function isEvent(expr, eventDeclarations) {
for (let {node, enclosingContract} of eventDeclarations) {
for (let { node, enclosingContract } of eventDeclarations) {
if (expr.callee.name === node.name && sourceCode.isAChildOf(expr, enclosingContract)) {
return true;
}
Expand All @@ -32,7 +32,7 @@ function create(context) {
// Stores each declared event in the file and its corresponding parent contract
function registerEventName(emitted) {
const { node } = emitted;
(!emitted.exit) && events.push({node, enclosingContract: sourceCode.getParent(node)});
(!emitted.exit) && events.push({ node, enclosingContract: sourceCode.getParent(node) });
}

function registerNonEmittedCallExpression(emitted) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/function-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ module.exports = {
return;
}

const {node} = emitted, {body} = node;
const { node } = emitted, { body } = node;
let cursor = 0;

// Filter out non-function nodes
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/imports-on-top.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = {
return;
}

const {node} = emitted,
const { node } = emitted,
programNode = context.getSourceCode().getParent(node),
indexOfNode = programNode.body.indexOf(node),
nodesAllowedAbove = ["ExperimentalPragmaStatement", "PragmaStatement", "ImportStatement"];
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-empty-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = {
}

function inspectBlockStatement(emitted) {
const {node} = emitted, {body} = node,
const { node } = emitted, { body } = node,
parent = context.getSourceCode().getParent(node);

if (emitted.exit || isFallbackFunc(parent) || isPayableFuncOrCons(parent)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/pragma-on-top.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module.exports = {
return;
}

const {node} = emitted,
const { node } = emitted,
nodesAllowedAbove = ["ExperimentalPragmaStatement", "PragmaStatement"],
programNode = context.getSourceCode().getParent(node);

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module.exports = {


function inspectImportStatement(emitted) {
const {node} = emitted,
const { node } = emitted,
nodeText = sourceCode.getText(node), expectedString = `${quote}${node.from}${quote}`;

// If using the expected quote style, exit now.
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
},
"scripts": {
"test": "nyc --reporter=text --reporter=html mocha --require should --reporter spec --recursive",
"lint": "eslint lib/ test/ bin/ config/"
"lint": "eslint lib/ test/ bin/ config/",
"lint-fix": "eslint lib/ test/ bin/ config/ --fix"
},
"keywords": [
"lint",
Expand Down
10 changes: 5 additions & 5 deletions test/lib/autofix/merge-fixer-packets.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ describe("check exposed API", function() {
// fixerPackets represent the outputs of the functions exposed by rule-fixer
// when a particular node & text are provided
let fixerPackets = [
rf.insertTextAfter({type: "a", start: 0, end: 3}, "123"),
rf.insertTextBefore({type: "a", start: 4, end: 6}, "@@@"),
rf.replaceText({type: "a", start: 8, end: 11}, "+++"),
rf.remove({type: "a", start: 12, end: 14}),
rf.insertTextAfter({ type: "a", start: 0, end: 3 }, "123"),
rf.insertTextBefore({ type: "a", start: 4, end: 6 }, "@@@"),
rf.replaceText({ type: "a", start: 8, end: 11 }, "+++"),
rf.remove({ type: "a", start: 12, end: 14 }),
rf.insertTextAfterRange([15, 16], "==="),
rf.insertTextBeforeRange([18, 22], "$$$"),
rf.removeRange([23, 25]),
Expand Down Expand Up @@ -79,7 +79,7 @@ describe("check exposed API", function() {

// overlapping ranges
mfp.bind(
mfp, [{range: [2, 5], text: ""}, {range: [4, 8], text: "%%%"}], "abcdefghijk"
mfp, [{ range: [2, 5], text: "" }, { range: [4, 8], text: "%%%" }], "abcdefghijk"
).should.throw();

done();
Expand Down
30 changes: 15 additions & 15 deletions test/lib/autofix/source-code-fixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("Test the source-code-fixer API", function() {
type: "error",
line: 1,
column: 4,
node: {type: "Literal", start: 1, end: 9}
node: { type: "Literal", start: 1, end: 9 }
}];

let msgsWithFixes = [{
Expand All @@ -33,8 +33,8 @@ describe("Test the source-code-fixer API", function() {
type: "error",
line: 1,
column: 4,
node: {type: "Literal", start: 1, end: 9},
fix: {range: [1, 4], text: ""}
node: { type: "Literal", start: 1, end: 9 },
fix: { range: [1, 4], text: "" }
}];

scf.applyFixes("", msgsNoFixes);
Expand Down Expand Up @@ -88,7 +88,7 @@ describe("Test the source-code-fixer API", function() {
type: "error",
line: 1,
column: 4,
node: {type: "Literal", start: 1, end: 9}
node: { type: "Literal", start: 1, end: 9 }
}];

let sourceCode = "abcd123@@@***&^###;;{}[]";
Expand Down Expand Up @@ -131,33 +131,33 @@ describe("Test the source-code-fixer API", function() {
type: "error",
line: 1,
column: 4,
node: {type: "Literal", start: 1, end: 9}
node: { type: "Literal", start: 1, end: 9 }
},
{
ruleName: "b",
message: "def",
type: "error",
line: 1,
column: 4,
node: {type: "Literal", start: 1, end: 9},
fix: {range: [3, 8], text: "***"} // replace
node: { type: "Literal", start: 1, end: 9 },
fix: { range: [3, 8], text: "***" } // replace
},
{
ruleName: "c",
message: "def",
type: "error",
line: 1,
column: 4,
node: {type: "Literal", start: 1, end: 9}
node: { type: "Literal", start: 1, end: 9 }
},
{
ruleName: "d",
message: "def",
type: "error",
line: 1,
column: 4,
node: {type: "Literal", start: 1, end: 9},
fix: {range: [8, 24], text: ""} // delete
node: { type: "Literal", start: 1, end: 9 },
fix: { range: [8, 24], text: "" } // delete
}
];

Expand Down Expand Up @@ -193,17 +193,17 @@ describe("Test the source-code-fixer API", function() {
type: "error",
line: 1,
column: 4,
node: {type: "Literal", start: 1, end: 9},
fix: {range: [5, 10], text: "^_^"} // shouldn't get applied
node: { type: "Literal", start: 1, end: 9 },
fix: { range: [5, 10], text: "^_^" } // shouldn't get applied
},
{
ruleName: "b",
message: "def",
type: "error",
line: 1,
column: 4,
node: {type: "Literal", start: 1, end: 9},
fix: {range: [3, 8], text: "***"}
node: { type: "Literal", start: 1, end: 9 },
fix: { range: [3, 8], text: "***" }
}
];

Expand Down Expand Up @@ -234,7 +234,7 @@ describe("Test the source-code-fixer API", function() {
// if rule ABC reports a fix inside an error object, and if that fix is an array of fixer packets,
// those packets must not have overlapping ranges.
scf.applyFixes.bind(scf,
[{range: [2, 5], text: ""}, {range: [4, 8], text: "%%%"}], "abcdefghijk"
[{ range: [2, 5], text: "" }, { range: [4, 8], text: "%%%" }], "abcdefghijk"
).should.throw();

done();
Expand Down
24 changes: 12 additions & 12 deletions test/lib/rule-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,45 +94,45 @@ describe("Testing RuleContext object", function() {
let sampleNode = { type: "Literal", start: 0, end: 10 };

rcObject.report.bind(rcObject, {}).should.throw();
rcObject.report.bind(rcObject, {message: 91072}).should.throw();
rcObject.report.bind(rcObject, {message: "hello", node: true}).should.throw();
rcObject.report.bind(rcObject, { message: 91072 }).should.throw();
rcObject.report.bind(rcObject, { message: "hello", node: true }).should.throw();
rcObject.report.bind(
rcObject,
{message: "hello", node: sampleNode, randomAttr: {}}
{ message: "hello", node: sampleNode, randomAttr: {} }
).should.throw();
rcObject.report.bind(
rcObject,
{message: "hello", node: sampleNode, location: {randomAttr: 1908}}
{ message: "hello", node: sampleNode, location: { randomAttr: 1908 } }
).should.throw();
rcObject.report.bind(
rcObject,
{message: "hello", node: sampleNode, location: {line: 90.1897}}
{ message: "hello", node: sampleNode, location: { line: 90.1897 } }
).should.throw();
rcObject.report.bind(
rcObject,
{message: "hello", node: sampleNode, location: {column: null}}
{ message: "hello", node: sampleNode, location: { column: null } }
).should.throw();
rcObject.report.bind(
rcObject,
{message: "hello", node: sampleNode, location: {line: 0}}
{ message: "hello", node: sampleNode, location: { line: 0 } }
).should.throw();
rcObject.report.bind(
rcObject,
{message: "hello", node: sampleNode, location: {column: -1}}
{ message: "hello", node: sampleNode, location: { column: -1 } }
).should.throw();
rcObject.report.bind(
rcObject,
{message: "hello", node: sampleNode, location: NaN}
{ message: "hello", node: sampleNode, location: NaN }
).should.throw();
rcObject.report.bind(
rcObject,
{message: "hello", node: sampleNode, fix: "this is a fix!!"}
{ message: "hello", node: sampleNode, fix: "this is a fix!!" }
).should.throw();

// A minimal valid object should not throw
rcObject.report.bind(
rcObject,
{message: "hello", node: sampleNode}
{ message: "hello", node: sampleNode }
).should.not.throw();

// A maximal valid object should not throw
Expand All @@ -157,7 +157,7 @@ describe("Testing RuleContext object", function() {
let rcObject = new RuleContext("foo", ruleDesc, meta, Solium);

rcObject.report({
node: {type: "TestNode", start: 0, end: 2},
node: { type: "TestNode", start: 0, end: 2 },
message: "test run"
});
let errorObjects = Solium.lint(sourceCode, { rules: {} }, true);
Expand Down
Loading

0 comments on commit 3b95a04

Please sign in to comment.