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

Increase code coverage #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .nycrc.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
include:
- src/**/*.js
exclude:
- src/index.js
reporter:
- lcov
- text-summary
Expand Down
5 changes: 5 additions & 0 deletions src/is-parenthesized.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function getParentSyntaxParen(node, sourceCode) {
return null

case "DoWhileStatement":
/* istanbul ignore else */
if (parent.test === node) {
return sourceCode.getTokenAfter(
parent.body,
Expand All @@ -32,24 +33,28 @@ function getParentSyntaxParen(node, sourceCode) {

case "IfStatement":
case "WhileStatement":
/* istanbul ignore else */
if (parent.test === node) {
return sourceCode.getFirstToken(parent, 1)
}
return null

case "ImportExpression":
/* istanbul ignore else */
if (parent.source === node) {
return sourceCode.getFirstToken(parent, 1)
}
return null

case "SwitchStatement":
/* istanbul ignore else */
if (parent.discriminant === node) {
return sourceCode.getFirstToken(parent, 1)
}
return null

case "WithStatement":
/* istanbul ignore else */
if (parent.object === node) {
return sourceCode.getFirstToken(parent, 1)
}
Expand Down
9 changes: 9 additions & 0 deletions test/get-property-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe("The 'getPropertyName' function", () => {
},
]
: []),
{ code: ";", expected: null },
]) {
it(`should return ${JSON.stringify(expected)} from ${code}`, () => {
const linter = new eslint.Linter()
Expand All @@ -65,12 +66,20 @@ describe("The 'getPropertyName' function", () => {
) {
actual = getPropertyName(node)
},
":not(Property,PropertyDefinition,MethodDefinition,MemberExpression)"(
node,
) {
if (!actual) {
actual = getPropertyName(node)
}
},
}))
const messages = linter.verify(code, {
parserOptions: {
ecmaVersion: semver.gte(eslint.Linter.version, "7.0.0")
? 2022
: 2018,
sourceType: "module",
},
rules: { test: "error" },
})
Expand Down
15 changes: 13 additions & 2 deletions test/is-parenthesized.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import eslint from "eslint"
import { isParenthesized } from "../src/"

describe("The 'isParenthesized' function", () => {
for (const { code, expected } of [
for (const { code, expected, sourceType, ecmaVersion } of [
{
code: "777",
expected: {
Expand Down Expand Up @@ -209,6 +209,14 @@ describe("The 'isParenthesized' function", () => {
"body.0.handler.param": false,
},
},
{
code: "import('./index.js')",
expected: {
"body.0.expression.source": false,
},
sourceType: "module",
ecmaVersion: 2022,
},
]) {
describe(`on the code \`${code}\``, () => {
for (const key of Object.keys(expected)) {
Expand All @@ -226,7 +234,10 @@ describe("The 'isParenthesized' function", () => {
}))
const messages = linter.verify(code, {
env: { es6: true },
parserOptions: { ecmaVersion: 2018 },
parserOptions: {
ecmaVersion: ecmaVersion ? ecmaVersion : 2018,
sourceType,
},
rules: { test: "error" },
})

Expand Down