Always use unpad (babel/babel-eslint#535)
This commit is contained in:
parent
f43062ebbb
commit
090269e5a0
@ -61,6 +61,7 @@ function lookup(obj, keypath, backwardsDepth) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseAndAssertSame(code) {
|
function parseAndAssertSame(code) {
|
||||||
|
code = unpad(code);
|
||||||
var esAST = espree.parse(code, {
|
var esAST = espree.parse(code, {
|
||||||
ecmaFeatures: {
|
ecmaFeatures: {
|
||||||
// enable JSX parsing
|
// enable JSX parsing
|
||||||
@ -177,30 +178,26 @@ describe("babylon-to-esprima", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("template also with braces #96", () => {
|
it("template also with braces #96", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
export default function f1() {
|
||||||
export default function f1() {
|
function f2(foo) {
|
||||||
function f2(foo) {
|
const bar = 3;
|
||||||
const bar = 3;
|
return \`\${foo} \${bar}\`;
|
||||||
return \`\${foo} \${bar}\`;
|
|
||||||
}
|
|
||||||
return f2;
|
|
||||||
}
|
}
|
||||||
`)
|
return f2;
|
||||||
);
|
}
|
||||||
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("template with destructuring #31", () => {
|
it("template with destructuring #31", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
module.exports = {
|
||||||
module.exports = {
|
render() {
|
||||||
render() {
|
var {name} = this.props;
|
||||||
var {name} = this.props;
|
return Math.max(null, \`Name: \${name}, Name: \${name}\`);
|
||||||
return Math.max(null, \`Name: \${name}, Name: \${name}\`);
|
}
|
||||||
}
|
};
|
||||||
};
|
`);
|
||||||
`)
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -301,40 +298,34 @@ describe("babylon-to-esprima", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("line comments", () => {
|
it("line comments", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
// single comment
|
||||||
// single comment
|
var foo = 15; // comment next to statement
|
||||||
var foo = 15; // comment next to statement
|
// second comment after statement
|
||||||
// second comment after statement
|
`);
|
||||||
`)
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("block comments", () => {
|
it("block comments", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
/* single comment */
|
||||||
/* single comment */
|
var foo = 15; /* comment next to statement */
|
||||||
var foo = 15; /* comment next to statement */
|
/*
|
||||||
/*
|
* multiline
|
||||||
* multiline
|
* comment
|
||||||
* comment
|
*/
|
||||||
*/
|
`);
|
||||||
`)
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("block comments #124", () => {
|
it("block comments #124", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
React.createClass({
|
||||||
React.createClass({
|
render() {
|
||||||
render() {
|
// return (
|
||||||
// return (
|
// <div />
|
||||||
// <div />
|
// ); // <-- this is the line that is reported
|
||||||
// ); // <-- this is the line that is reported
|
}
|
||||||
}
|
});
|
||||||
});
|
`);
|
||||||
`)
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("null", () => {
|
it("null", () => {
|
||||||
@ -374,43 +365,37 @@ describe("babylon-to-esprima", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("jsdoc", () => {
|
it("jsdoc", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
/**
|
||||||
/**
|
* @param {object} options
|
||||||
* @param {object} options
|
* @return {number}
|
||||||
* @return {number}
|
*/
|
||||||
*/
|
const test = function({ a, b, c }) {
|
||||||
const test = function({ a, b, c }) {
|
return a + b + c;
|
||||||
return a + b + c;
|
};
|
||||||
};
|
module.exports = test;
|
||||||
module.exports = test;
|
`);
|
||||||
`)
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("empty block with comment", () => {
|
it("empty block with comment", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
function a () {
|
||||||
function a () {
|
try {
|
||||||
try {
|
b();
|
||||||
b();
|
} catch (e) {
|
||||||
} catch (e) {
|
// asdf
|
||||||
// asdf
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
`)
|
}
|
||||||
);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("babel tests", () => {
|
describe("babel tests", () => {
|
||||||
it("MethodDefinition", () => {
|
it("MethodDefinition", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
export default class A {
|
||||||
export default class A {
|
a() {}
|
||||||
a() {}
|
}
|
||||||
}
|
`);
|
||||||
`)
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("MethodDefinition 2", () => {
|
it("MethodDefinition 2", () => {
|
||||||
@ -420,43 +405,37 @@ describe("babylon-to-esprima", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("ClassMethod", () => {
|
it("ClassMethod", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
class A {
|
||||||
class A {
|
constructor() {
|
||||||
constructor() {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
`)
|
}
|
||||||
);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("ClassMethod multiple params", () => {
|
it("ClassMethod multiple params", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
class A {
|
||||||
class A {
|
constructor(a, b, c) {
|
||||||
constructor(a, b, c) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
`)
|
}
|
||||||
);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("ClassMethod multiline", () => {
|
it("ClassMethod multiline", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
class A {
|
||||||
class A {
|
constructor (
|
||||||
constructor (
|
a,
|
||||||
a,
|
b,
|
||||||
b,
|
c
|
||||||
c
|
)
|
||||||
)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
`)
|
}
|
||||||
);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("ClassMethod oneline", () => {
|
it("ClassMethod oneline", () => {
|
||||||
@ -464,14 +443,12 @@ describe("babylon-to-esprima", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("ObjectMethod", () => {
|
it("ObjectMethod", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
var a = {
|
||||||
var a = {
|
b(c) {
|
||||||
b(c) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
`)
|
}
|
||||||
);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("do not allow import export everywhere", () => {
|
it("do not allow import export everywhere", () => {
|
||||||
@ -496,41 +473,35 @@ describe("babylon-to-esprima", () => {
|
|||||||
|
|
||||||
it("getters and setters", () => {
|
it("getters and setters", () => {
|
||||||
parseAndAssertSame("class A { get x ( ) { ; } }");
|
parseAndAssertSame("class A { get x ( ) { ; } }");
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
class A {
|
||||||
class A {
|
get x(
|
||||||
get x(
|
)
|
||||||
)
|
{
|
||||||
{
|
;
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
`)
|
}
|
||||||
);
|
`);
|
||||||
parseAndAssertSame("class A { set x (a) { ; } }");
|
parseAndAssertSame("class A { set x (a) { ; } }");
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
class A {
|
||||||
class A {
|
set x(a
|
||||||
set x(a
|
)
|
||||||
)
|
{
|
||||||
{
|
;
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
`)
|
}
|
||||||
);
|
`);
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
var B = {
|
||||||
var B = {
|
get x () {
|
||||||
get x () {
|
return this.ecks;
|
||||||
return this.ecks;
|
},
|
||||||
},
|
set x (ecks) {
|
||||||
set x (ecks) {
|
this.ecks = ecks;
|
||||||
this.ecks = ecks;
|
}
|
||||||
}
|
};
|
||||||
};
|
`);
|
||||||
`)
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("RestOperator", () => {
|
it("RestOperator", () => {
|
||||||
@ -546,13 +517,11 @@ describe("babylon-to-esprima", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Async/Await", () => {
|
it("Async/Await", () => {
|
||||||
parseAndAssertSame(
|
parseAndAssertSame(`
|
||||||
unpad(`
|
async function a() {
|
||||||
async function a() {
|
await 1;
|
||||||
await 1;
|
}
|
||||||
}
|
`);
|
||||||
`)
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user