Skip to content

Commit

Permalink
Return null for name of destructed and aliased
Browse files Browse the repository at this point in the history
  • Loading branch information
zcuric committed Feb 10, 2020
1 parent 65c5eee commit 5e701a2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 257 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ module.exports = {
const name = isAssignmentPattern(value)
? value.left.name
: value.name;
return ignoreCase ? name.toLowerCase() : name;
if (name) return ignoreCase ? name.toLowerCase() : name;
return null;
};

const sortByName = (propertyA, propertyB) => {
Expand Down
261 changes: 5 additions & 256 deletions test/require-sort.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ ruleTester.run('require-sort', rule, {
code: `
const a = require('bar');
const b = require('foo');
if (bar) {
const c = require('baz');
}
Expand Down Expand Up @@ -152,6 +151,11 @@ ruleTester.run('require-sort', rule, {
const { a, b, c } = require('bar');
`
}),
test({
code: `
const { a, b: { d: e }, c } = require('bar');
`
}),
test({
code: `
const { b, c, a } = require('bar');
Expand Down Expand Up @@ -286,258 +290,3 @@ ruleTester.run('require-sort', rule, {
})
])
});

// ruleTester.run('require-sort', rule, {
// valid: [
// {
// code:
// "const A = require('bar.js');\n" +
// "const {b, c} = require('foo.js');",
// options: [{
// propertySyntaxSortOrder: ['none', 'single', 'multiple']
// }]
// },
// {
// code:
// "const a = require('foo.js');\n" +
// "const B = require('bar.js');",
// options: ignoreCaseArgs
// },
// {
// code:
// "const a = require('foo.js');\n" +
// "const B = require('bar.js');",
// options: [{
// ignoreDeclarationSort: true
// }]
// },
// {
// code: "const {b, A, C, d} = require('foo.js');",
// options: [{
// ignorePropertySort: true
// }]
// },
// {
// code: "const {B, a, C, d} = require('foo.js');",
// options: [{
// ignorePropertySort: true
// }]
// },
// {
// code: "const {a, B, c, D} = require('foo.js');",
// options: ignoreCaseArgs
// },
// {
// code:
// "require('bar.js');\n" +
// "const {b, c} = require('foo.js');",
// options: [{
// propertySyntaxSortOrder: ['none', 'multiple', 'single']
// }]
// },
// {
// code: `
// const { b: a } = require('foo.js');
// const { a: b } = require('foo.js');
// `
// },
// {
// code: `
// const { a: b = {} } = require('foo');
// const c = require('bar');
// const d = require('baz');
// const { e } = require('foobar');
// `,
// options: ignoreCaseArgs
// }
// ],
// invalid: [
// {
// code:
// "const a = require('foo.js');\n" +
// "const A = require('bar.js');",
// output: null,
// errors: [expectedError]
// },
// {
// code: `
// const { a: z = {} } = require('foo');
// const c = require('bar');
// const d = require('baz');
// const { e } = require('foobar');
// `,
// output: null,
// errors: [expectedError]
// },
// {
// code:
// "const a = require('foo');\n" +
// "require('muu');",
// output: null,
// errors: [{
// message: "Expected 'none' syntax before 'single' syntax.",
// type: 'CallExpression'
// }]
// },
// {
// code:
// "const b = require('foo.js');\n" +
// "const a = require('bar.js');",
// output: null,
// errors: [expectedError]
// },
// {
// code:
// "const {b, c} = require('foo.js');\n" +
// "const {a, d} = require('bar.js');",
// output: null,
// errors: [expectedError]
// },
// {
// code:
// "const a = require('foo.js');\n" +
// "const {b, c} = require('bar.js');",
// output: null,
// errors: [{
// message: "Expected 'multiple' syntax before 'single' syntax.",
// type: 'VariableDeclaration'
// }]
// },
// {
// code: "const {b, a, d, c} = require('foo.js');",
// output: "const {a, b, c, d} = require('foo.js');",
// errors: [{
// message: "Property 'a' of the require declaration should be sorted alphabetically.",
// type: 'Property'
// }]
// },
// {
// code: "const {b, d: a, c} = require('foo.js');",
// output: "const {d: a, b, c} = require('foo.js');",
// errors: [{
// message: "Property 'a' of the require declaration should be sorted alphabetically.",
// type: 'Property'
// }]
// },
// {
// code: "const {b, d: a = {}, c} = require('foo.js');",
// output: "const {d: a = {}, b, c} = require('foo.js');",
// errors: [{
// message: "Property 'a' of the require declaration should be sorted alphabetically.",
// type: 'Property'
// }]
// },
// {
// code: `
// const { a: b } = require('foo.js');
// const { b: a } = require('foo.js');
// `,
// output: `
// const { a: b } = require('foo.js');
// const { b: a } = require('foo.js');
// `,
// errors: [expectedError]
// },
// {
// code:
// "const {b, a, d, c} = require('foo.js');\n" +
// "const {e, f, g, h} = require('bar.js');",
// output:
// "const {a, b, c, d} = require('foo.js');\n" +
// "const {e, f, g, h} = require('bar.js');",
// options: [{ ignoreDeclarationSort: true }],
// errors: [{
// message: "Property 'a' of the require declaration should be sorted alphabetically.",
// type: 'Property'
// }]
// },
// {
// code: "const {a, B, c, D} = require('foo.js');",
// output: "const {B, D, a, c} = require('foo.js');",
// errors: [{
// message: "Property 'B' of the require declaration should be sorted alphabetically.",
// type: 'Property'
// }]
// },
// {
// code: "const {zzzzz, /* comment */ aaaaa} = require('foo.js');",
// output: null, // not fixed due to comment
// errors: [{
// message: "Property 'aaaaa' of the require declaration should be sorted alphabetically.",
// type: 'Property'
// }]
// },
// {
// code: "const {zzzzz /* comment */, aaaaa} = require('foo.js');",
// output: null, // not fixed due to comment
// errors: [{
// message: "Property 'aaaaa' of the require declaration should be sorted alphabetically.",
// type: 'Property'
// }]
// },
// {
// code: "const {/* comment */ zzzzz, aaaaa} = require('foo.js');",
// output: null, // not fixed due to comment
// errors: [{
// message: "Property 'aaaaa' of the require declaration should be sorted alphabetically.",
// type: 'Property'
// }]
// },
// {
// code: "const {zzzzz, aaaaa /* comment */} = require('foo.js');",
// output: null, // not fixed due to comment
// errors: [{
// message: "Property 'aaaaa' of the require declaration should be sorted alphabetically.",
// type: 'Property'
// }]
// },
// {
// code: `
// const bar = require('bar');
// const foo = require('foo');
// function fn() { let baz = require('baz'); }`,
// output: `
// const bar = require('bar');
// const foo = require('foo');
// function fn() { let baz = require('baz'); }`,
// errors: []
// },
// {
// code: `
// const bar = require('bar');
// const foo = require('foo');
// if (foo) { let baz = require('baz'); }`,
// output: `
// const bar = require('bar');
// const foo = require('foo');
// if (foo) { let baz = require('baz'); }`,
// errors: []
// },
// {
// code: `
// const {
// boop,
// foo,
// zoo,
// qux,
// bar,
// beep
// } = require('foo.js');
// `,
// output: `
// const {
// bar,
// beep,
// boop,
// foo,
// qux,
// zoo
// } = require('foo.js');
// `,
// errors: [{
// message: "Property 'qux' of the require declaration should be sorted alphabetically.",
// type: 'Property'
// }]
// }
// ]
// });

0 comments on commit 5e701a2

Please sign in to comment.