mirror of
https://github.com/hanzoai/eslint.git
synced 2026-10-30 19:38:10 +00:00
63 lines
1.4 KiB
JavaScript
63 lines
1.4 KiB
JavaScript
/**
|
|
* @fileoverview Disallow string concatenation when using __dirname and __filename
|
|
* @author Nicholas C. Zakas
|
|
*/
|
|
"use strict";
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Requirements
|
|
//------------------------------------------------------------------------------
|
|
|
|
const rule = require("../../../lib/rules/no-path-concat"),
|
|
RuleTester = require("../../../lib/rule-tester/rule-tester");
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Tests
|
|
//------------------------------------------------------------------------------
|
|
|
|
const ruleTester = new RuleTester();
|
|
|
|
ruleTester.run("no-path-concat", rule, {
|
|
valid: [
|
|
'var fullPath = dirname + "foo.js";',
|
|
'var fullPath = __dirname == "foo.js";',
|
|
"if (fullPath === __dirname) {}",
|
|
"if (__dirname === fullPath) {}",
|
|
],
|
|
|
|
invalid: [
|
|
{
|
|
code: 'var fullPath = __dirname + "/foo.js";',
|
|
errors: [
|
|
{
|
|
messageId: "usePathFunctions",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: 'var fullPath = __filename + "/foo.js";',
|
|
errors: [
|
|
{
|
|
messageId: "usePathFunctions",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: 'var fullPath = "/foo.js" + __filename;',
|
|
errors: [
|
|
{
|
|
messageId: "usePathFunctions",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: 'var fullPath = "/foo.js" + __dirname;',
|
|
errors: [
|
|
{
|
|
messageId: "usePathFunctions",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|