本文整理汇总了TypeScript中eslint.RuleTester类的典型用法代码示例。如果您正苦于以下问题:TypeScript RuleTester类的具体用法?TypeScript RuleTester怎么用?TypeScript RuleTester使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RuleTester类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: RuleTester
import { RuleTester } from "eslint";
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018 } });
import { rule } from "../../src/rules/code-eval";
ruleTester.run("Dynamically executing code is security-sensitive", rule, {
valid: [
{
code: `foo(x)`,
},
{
code: `function foo(x){}\n foo(x);`,
},
{
code: `eval()`,
},
{
code: `eval(42)`,
},
{
code: `eval("Hello")`,
},
{
code: `eval(\`Hello\`)`,
},
{
code: `Function()`,
},
{
code: `new Function(42)`,
},
开发者ID:SonarSource,项目名称:sonar-javascript,代码行数:31,代码来源:code-eval.test.ts
示例2: RuleTester
import { RuleTester } from "eslint";
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018, sourceType: "module" } });
import { rule } from "../../src/rules/hashing";
ruleTester.run("Hashing data is security-sensitive: client side", rule, {
valid: [
{
// no call
code: `crypto.subtle.digest`,
},
{
// not "digest"
code: `crypto.subtle.encrypt()`,
},
{
// no "crypto.subtle"
code: `foo.digest()`,
},
],
invalid: [
{
code: `crypto.subtle.digest("SHA-256", buffer);`,
errors: [
{
message: "Make sure that hashing data is safe here.",
line: 1,
endLine: 1,
column: 1,
endColumn: 21,
},
开发者ID:SonarSource,项目名称:sonar-javascript,代码行数:31,代码来源:hashing.test.ts
示例3: RuleTester
import { RuleTester } from "eslint";
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018, sourceType: "module" } });
import { rule } from "../../src/rules/http-requests";
ruleTester.run("Sending HTTP requests is security-sensitive: client side", rule, {
valid: [
// no call to XMLHttpRequest constructor
{
code: `xmlhttp.open("GET", url, false);`,
},
{
code: `myFetch()`,
},
],
invalid: [
{
code: `window.fetch(url);`,
errors: [
{
message: "Make sure that this HTTP request is sent safely.",
line: 1,
endLine: 1,
column: 1,
endColumn: 13,
},
],
},
{
code: `fetch(url);`,
errors: 1,
开发者ID:SonarSource,项目名称:sonar-javascript,代码行数:31,代码来源:http-requests.test.ts
示例4: RuleTester
import { RuleTester } from "eslint";
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018, sourceType: "module" } });
import { rule } from "../../src/rules/file-handling";
ruleTester.run("Handling files is security-sensitive", rule, {
valid: [
{
code: `
const fs = require('fs');
fs.createWriteStream('foo.txt');
`,
},
{
code: `
const fs = require('myFs');
fs.createWriteStream(userInput + ".txt");
`,
},
{
code: `
import { rename } from 'fs'
rename("foo.txt", "bar.txt")
`,
},
{
code: `
const fs = require('fs');
fs[getFunctionName()]('foo.txt');
`,
},
开发者ID:SonarSource,项目名称:sonar-javascript,代码行数:31,代码来源:file-handling.test.ts
示例5: RuleTester
import { RuleTester } from "eslint";
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018, sourceType: "module" } });
import { rule } from "../../src/rules/os-command";
ruleTester.run("Executing OS commands is security-sensitive", rule, {
valid: [
{
code: `
const cp = require('child_process');
cp.fork('child.js');
`,
},
{
code: `
import { fork } from 'child_process';
fork('child.js');`,
},
{
code: `
const cp = require('child_process');
cp.exec('echo child_process.exec hardcoded >> output.txt');`,
},
{
code: `
const cp = require('child_process');
cp.spawn('echo child_process.exec hardcoded >> output.txt', { shell: true });`,
},
{
code: `
const cp = require('child_process');
开发者ID:SonarSource,项目名称:sonar-javascript,代码行数:31,代码来源:os-command.test.ts
示例6: RuleTester
import { RuleTester } from "eslint";
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018, sourceType: "module" } });
import { rule } from "../../src/rules/sql-queries";
ruleTester.run("Executing SQL queries is security-sensitive", rule, {
valid: [
{
code: `
const mysql = require('mysql');
conn.query(sql, [userInput], (err, res) => {});
`,
},
{
code: `
const pg = require('pg');
conn.query(sql, [userInput], (err, res) => {});
`,
},
{
code: `
const pg = require('pg');
conn.query("SELECT * FROM FOO", (err, res) => {});
`,
},
{
code: `
import { query } from 'myDB';
query("SELECT * FROM users WHERE id = ' + userId", (err, res) => {});
`,
},
开发者ID:SonarSource,项目名称:sonar-javascript,代码行数:31,代码来源:sql-queries.test.ts
示例7: RuleTester
import { RuleTester } from "eslint";
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018, sourceType: "module" } });
import { rule } from "../../src/rules/regular-expr";
ruleTester.run("Using regular expressions is security-sensitive", rule, {
valid: [
{
code: `str.replace("foo", str); str.replace('foo', str);`,
},
{
code: `let regex = /ab+c/; `,
},
{
code: `str.split();`,
},
{
code: `foo.test();`,
},
{
code: `foo.test(p1, p2);`,
},
{
code: `/abc/.test(p1);`,
},
{
code: `/abc/g.test(p1);`,
},
{
code: `/./.test(p1);`,
},
开发者ID:SonarSource,项目名称:sonar-javascript,代码行数:31,代码来源:regular-expr.test.ts
示例8: RuleTester
import { RuleTester } from "eslint";
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018 } });
import { rule } from "../../src/rules/process-argv";
ruleTester.run("Using command line arguments is security-sensitive", rule, {
valid: [
{
code: `foo.bar`,
},
{
code: `process.argvFoo`,
},
{
code: `processFoo.argv`,
},
{
code: `'process.argv'`,
},
],
invalid: [
{
code: `let x = process.argv;`,
errors: [
{
message: "Make sure that command line arguments are used safely here.",
line: 1,
endLine: 1,
column: 9,
endColumn: 21,
},
开发者ID:SonarSource,项目名称:sonar-javascript,代码行数:31,代码来源:process-argv.test.ts
示例9: RuleTester
import { RuleTester } from "eslint";
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018 } });
import { rule } from "../../src/rules/cookies";
ruleTester.run("Using cookies is security-sensitive", rule, {
valid: [
{
code: `document.foo`,
},
{
code: `foo.cookie`,
},
{
code: `response.setHeader()`,
},
{
code: `response.setHeader('Content-Type', 'text/plain')`,
},
{
code: `response.foo('Set-Cookie', x)`,
},
{
code: `response.setHeader(SetCookie, x)`,
},
{
code: `res.cookie("foo", "bar");`,
},
{
code: `foo(req.cookies);`,
},
开发者ID:SonarSource,项目名称:sonar-javascript,代码行数:31,代码来源:cookies.test.ts
示例10: RuleTester
import { RuleTester } from "eslint";
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018, sourceType: "module" } });
import { rule } from "../../src/rules/http-endpoint";
ruleTester.run("Exposing HTTP endpoints is security-sensitive", rule, {
valid: [
{
code: `import * as express from 'foo'; app.listen(3000);`,
},
{
code: `import * as express from 'foo'; listen(3000);`,
},
{
code: `import * as exp from 'express'; app.use(foo);`,
},
{
code: `import * as express from 'express'; app.listen;`,
},
{
code: `foo('express'); app.listen(3000);`,
},
{
code: `require('express'); app.use(3000);`,
},
],
invalid: [
{
code: `import { foo } from "http"; bar.listen(3000);`,
errors: [
{
开发者ID:SonarSource,项目名称:sonar-javascript,代码行数:31,代码来源:http-endpoint.test.ts
注:本文中的eslint.RuleTester类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论