Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make rule no-useless-path-segments work with commonjs #1128

Merged
merged 1 commit into from
Jul 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/rules/no-useless-path-segments.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ module.exports = {
url: docsUrl('no-useless-path-segments'),
},

schema: [
{
type: 'object',
properties: {
commonjs: { type: 'boolean' },
},
additionalProperties: false,
},
],

fixable: 'code',
},

Expand Down
47 changes: 47 additions & 0 deletions tests/src/rules/no-useless-path-segments.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const rule = require('rules/no-useless-path-segments')
function runResolverTests(resolver) {
ruleTester.run(`no-useless-path-segments (${resolver})`, rule, {
valid: [
// commonjs with default options
test({ code: 'require("./../files/malformed.js")' }),

// esmodule
test({ code: 'import "./malformed.js"' }),
test({ code: 'import "./test-module"' }),
test({ code: 'import "./bar/"' }),
Expand All @@ -16,6 +20,49 @@ function runResolverTests(resolver) {
],

invalid: [
// commonjs
test({
code: 'require("./../files/malformed.js")',
options: [{ commonjs: true }],
errors: [ 'Useless path segments for "./../files/malformed.js", should be "../files/malformed.js"'],
}),
test({
code: 'require("./../files/malformed")',
options: [{ commonjs: true }],
errors: [ 'Useless path segments for "./../files/malformed", should be "../files/malformed"'],
}),
test({
code: 'require("../files/malformed.js")',
options: [{ commonjs: true }],
errors: [ 'Useless path segments for "../files/malformed.js", should be "./malformed.js"'],
}),
test({
code: 'require("../files/malformed")',
options: [{ commonjs: true }],
errors: [ 'Useless path segments for "../files/malformed", should be "./malformed"'],
}),
test({
code: 'require("./test-module/")',
options: [{ commonjs: true }],
errors: [ 'Useless path segments for "./test-module/", should be "./test-module"'],
}),
test({
code: 'require("./")',
options: [{ commonjs: true }],
errors: [ 'Useless path segments for "./", should be "."'],
}),
test({
code: 'require("../")',
options: [{ commonjs: true }],
errors: [ 'Useless path segments for "../", should be ".."'],
}),
test({
code: 'require("./deep//a")',
options: [{ commonjs: true }],
errors: [ 'Useless path segments for "./deep//a", should be "./deep/a"'],
}),

// esmodule
test({
code: 'import "./../files/malformed.js"',
errors: [ 'Useless path segments for "./../files/malformed.js", should be "../files/malformed.js"'],
Expand Down