mirror of
https://github.com/hanzoai/eslint.git
synced 2026-10-30 19:38:10 +00:00
165 lines
2.8 KiB
JavaScript
165 lines
2.8 KiB
JavaScript
/**
|
|
* @fileoverview Tests for no-bitwise rule.
|
|
* @author Nicholas C. Zakas
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Requirements
|
|
//------------------------------------------------------------------------------
|
|
|
|
const rule = require("../../../lib/rules/no-bitwise"),
|
|
RuleTester = require("../../../lib/rule-tester/rule-tester");
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Tests
|
|
//------------------------------------------------------------------------------
|
|
|
|
const ruleTester = new RuleTester();
|
|
|
|
ruleTester.run("no-bitwise", rule, {
|
|
valid: [
|
|
"a + b",
|
|
"!a",
|
|
"a && b",
|
|
"a || b",
|
|
"a += b",
|
|
{ code: "a &&= b", languageOptions: { ecmaVersion: 2021 } },
|
|
{ code: "a ||= b", languageOptions: { ecmaVersion: 2021 } },
|
|
{ code: "a ??= b", languageOptions: { ecmaVersion: 2021 } },
|
|
{ code: "~[1, 2, 3].indexOf(1)", options: [{ allow: ["~"] }] },
|
|
{ code: "~1<<2 === -8", options: [{ allow: ["~", "<<"] }] },
|
|
{ code: "a|0", options: [{ int32Hint: true }] },
|
|
{ code: "a|0", options: [{ allow: ["|"], int32Hint: false }] },
|
|
],
|
|
invalid: [
|
|
{
|
|
code: "a ^ b",
|
|
errors: [
|
|
{
|
|
messageId: "unexpected",
|
|
data: { operator: "^" },
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "a | b",
|
|
errors: [
|
|
{
|
|
messageId: "unexpected",
|
|
data: { operator: "|" },
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "a & b",
|
|
errors: [
|
|
{
|
|
messageId: "unexpected",
|
|
data: { operator: "&" },
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "a << b",
|
|
errors: [
|
|
{
|
|
messageId: "unexpected",
|
|
data: { operator: "<<" },
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "a >> b",
|
|
errors: [
|
|
{
|
|
messageId: "unexpected",
|
|
data: { operator: ">>" },
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "a >>> b",
|
|
errors: [
|
|
{
|
|
messageId: "unexpected",
|
|
data: { operator: ">>>" },
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "a|0",
|
|
errors: [
|
|
{
|
|
messageId: "unexpected",
|
|
data: { operator: "|" },
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "~a",
|
|
errors: [
|
|
{
|
|
messageId: "unexpected",
|
|
data: { operator: "~" },
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "a ^= b",
|
|
errors: [
|
|
{
|
|
messageId: "unexpected",
|
|
data: { operator: "^=" },
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "a |= b",
|
|
errors: [
|
|
{
|
|
messageId: "unexpected",
|
|
data: { operator: "|=" },
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "a &= b",
|
|
errors: [
|
|
{
|
|
messageId: "unexpected",
|
|
data: { operator: "&=" },
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "a <<= b",
|
|
errors: [
|
|
{
|
|
messageId: "unexpected",
|
|
data: { operator: "<<=" },
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "a >>= b",
|
|
errors: [
|
|
{
|
|
messageId: "unexpected",
|
|
data: { operator: ">>=" },
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "a >>>= b",
|
|
errors: [
|
|
{
|
|
messageId: "unexpected",
|
|
data: { operator: ">>>=" },
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|