New: Update from sonarwhal to webhint
This commit is contained in:
Родитель
ab94202114
Коммит
b52a5260f4
|
@ -2,11 +2,12 @@
|
|||
*.log
|
||||
*.pid
|
||||
*.STALE
|
||||
hints/*/.eslintcache
|
||||
.DS_Store
|
||||
.nyc_output
|
||||
/.vscode/
|
||||
/build/
|
||||
/coverage/
|
||||
rules/*/node_modules/
|
||||
rules/*/dist/
|
||||
hints/*/node_modules/
|
||||
hints/*/dist/
|
||||
|
||||
|
|
10
README.md
10
README.md
|
@ -1,11 +1,11 @@
|
|||
# Microsoft sonarwhal rules
|
||||
# Microsoft webhint hints
|
||||
|
||||
This repository contains rules specific to Microsoft projects.
|
||||
This repository contains hints specific to Microsoft projects.
|
||||
|
||||
To know more about each rule package, visit their respective `readme.md`:
|
||||
To know more about each hint package, visit their respective `readme.md`:
|
||||
|
||||
* [chisel](./rules/chisel/README.md)
|
||||
* [jsll](./rules/jsll/README.md)
|
||||
* [chisel](./hints/chisel/README.md)
|
||||
* [jsll](./hints/jsll/README.md)
|
||||
|
||||
# Contributing
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
},
|
||||
"formatters": "stylish",
|
||||
"parsers": [],
|
||||
"rulesTimeout": 120000,
|
||||
"rules": {
|
||||
"hintsTimeout": 120000,
|
||||
"hints": {
|
||||
"chisel": "warning"
|
||||
}
|
||||
}
|
|
@ -2,24 +2,24 @@
|
|||
|
||||
Use Chisel to assess the accessibility of a web site or web application.
|
||||
|
||||
In order to install this rule you need to be a Microsoft employee and
|
||||
In order to install this hint you need to be a Microsoft employee and
|
||||
have access to the `chisel` registry, otherwise you'll have errors during
|
||||
the installation.
|
||||
|
||||
## Can the rule be configured?
|
||||
## Can the hint be configured?
|
||||
|
||||
Yes, you can configure this rule in your `sonarwhal` configuration file as
|
||||
Yes, you can configure this hint in your `webhint` configuration file as
|
||||
follows:
|
||||
|
||||
```json
|
||||
"rules": {
|
||||
"hints": {
|
||||
"chisel": ["warning", { "testsToRun": "color-contrast"}]
|
||||
}
|
||||
```
|
||||
|
||||
The available parameters include:
|
||||
|
||||
* `testsToRun?`: `string[]` - (Optional) Used to set the rules that will be run
|
||||
* `testsToRun?`: `string[]` - (Optional) Used to set the hints that will be run
|
||||
in chisel test run.
|
||||
|
||||
* `dom?`: `NodeSelector & Node | NodeList` - (Optional) Used to set the elements
|
||||
|
@ -37,6 +37,6 @@ The available parameters include:
|
|||
elements that will not be tested and can be used with include; ignored if
|
||||
dom or selector are set.
|
||||
|
||||
* `enableBestPracticeRules?`: `boolean` - (Optional, default is `false`) Enables
|
||||
rule that are not mapped to MAS/considered best practice; default is false
|
||||
* `enableBestPracticeHints?`: `boolean` - (Optional, default is `false`) Enables
|
||||
hint that are not mapped to MAS/considered best practice; default is false
|
||||
and ignored if testsToRun is set.
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -12,10 +12,12 @@
|
|||
"timeout": "1m"
|
||||
},
|
||||
"dependencies": {
|
||||
"@mskeros/chisel": "^1.132.3"
|
||||
"@mskeros/chisel": "^1.141.1"
|
||||
},
|
||||
"description": "sonarwhal rule to assess the accessibility of a web site using Microsoft's Chisel.",
|
||||
"description": "webhint hint to assess the accessibility of a web site using Microsoft's Chisel.",
|
||||
"devDependencies": {
|
||||
"@hint/parser-javascript": "^1.0.1",
|
||||
"@hint/utils-tests-helpers": "^1.0.1",
|
||||
"@types/debug": "0.0.30",
|
||||
"@types/node": "8.0.14",
|
||||
"async-retry": "^1.1.4",
|
||||
|
@ -29,12 +31,12 @@
|
|||
"eslint-plugin-markdown": "^1.0.0-beta.6",
|
||||
"eslint-plugin-typescript": "^0.8.1",
|
||||
"express": "^4.16.2",
|
||||
"hint": "^3.4.0",
|
||||
"markdownlint-cli": "^0.6.0",
|
||||
"npm-run-all": "^4.1.2",
|
||||
"nyc": "^11.4.1",
|
||||
"on-headers": "^1.0.1",
|
||||
"rimraf": "^2.6.2",
|
||||
"sonarwhal": "^1.0.0",
|
||||
"typescript": "^2.6.2",
|
||||
"typescript-eslint-parser": "^12.0.0"
|
||||
},
|
||||
|
@ -45,21 +47,21 @@
|
|||
"dist/src",
|
||||
"npm-shrinkwrap.json"
|
||||
],
|
||||
"homepage": "https://sonarwhal.com",
|
||||
"homepage": "https://webhint.io",
|
||||
"keywords": [
|
||||
"chisel",
|
||||
"rule",
|
||||
"sonarwhal",
|
||||
"sonarwhal-chisel"
|
||||
"hint",
|
||||
"webhint",
|
||||
"webhint-chisel"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"main": "dist/src/index.js",
|
||||
"name": "sonarwhal-rule-chisel",
|
||||
"name": "webhint-hint-chisel",
|
||||
"peerDependencies": {
|
||||
"sonarwhal": "^1.0.0",
|
||||
"@sonarwhal/parser-javascript": "^2.0.0"
|
||||
"hint": "^3.4.0",
|
||||
"@hint/parser-javascript": "^1.0.1"
|
||||
},
|
||||
"repository": "Microsoft/sonarwhal-microsoft-rules",
|
||||
"repository": "Microsoft/webhint-hints-microsoft",
|
||||
"scripts": {
|
||||
"build": "npm run clean && npm-run-all build:*",
|
||||
"build-release": "npm run clean && npm run build:assets && tsc --inlineSourceMap false --removeComments true",
|
||||
|
@ -74,7 +76,7 @@
|
|||
"watch:assets": "npm run build:assets -- -w --no-initial",
|
||||
"watch:test": "ava --watch",
|
||||
"watch:ts": "npm run build:ts -- --watch",
|
||||
"sonarwhal": "node node_modules/sonarwhal/dist/src/bin/sonarwhal.js"
|
||||
"webhint": "node node_modules/hint/dist/src/bin/hint.js"
|
||||
},
|
||||
"version": "1.0.0"
|
||||
"version": "2.0.0"
|
||||
}
|
|
@ -2,13 +2,13 @@
|
|||
* @fileoverview Use Chisel to assess the accessibility of a web site or web application.
|
||||
*/
|
||||
|
||||
import { Category } from 'sonarwhal/dist/src/lib/enums/category';
|
||||
import { RuleContext } from 'sonarwhal/dist/src/lib/rule-context';
|
||||
import { RuleMetadata, TraverseEnd, IAsyncHTMLElement, Severity } from 'sonarwhal/dist/src/lib/types';
|
||||
import { debug as d } from 'sonarwhal/dist/src/lib/utils/debug';
|
||||
import { Category } from 'hint/dist/src/lib/enums/category';
|
||||
import { HintContext } from 'hint/dist/src/lib/hint-context';
|
||||
import { HintMetadata, TraverseEnd, IAsyncHTMLElement, Severity } from 'hint/dist/src/lib/types';
|
||||
import { debug as d } from 'hint/dist/src/lib/utils/debug';
|
||||
import { IChiselResults, AxeNodeResult, AxeRule, IChiselDecorations, IChiselOptions } from '@mskeros/chisel/chisel';
|
||||
import { readFileAsync } from 'sonarwhal/dist/src/lib/utils/misc';
|
||||
import { RuleScope } from 'sonarwhal/dist/src/lib/enums/rulescope';
|
||||
import readFileAsync from 'hint/dist/src/lib/utils/fs/read-file-async';
|
||||
import { HintScope } from 'hint/dist/src/lib/enums/hintscope';
|
||||
|
||||
|
||||
const debug: debug.IDebugger = d(__filename);
|
||||
|
@ -18,8 +18,8 @@ const debug: debug.IDebugger = d(__filename);
|
|||
* Public
|
||||
* ------------------------------------------------------------------------------
|
||||
*/
|
||||
export default class ChiselRule {
|
||||
public static readonly meta: RuleMetadata = {
|
||||
export default class ChiselHint {
|
||||
public static readonly meta: HintMetadata = {
|
||||
docs: {
|
||||
category: Category.accessibility,
|
||||
description: `Use Chisel to assess the accessibility of a web site or web application.`
|
||||
|
@ -29,7 +29,7 @@ export default class ChiselRule {
|
|||
additionalProperties: false,
|
||||
properties: {
|
||||
dom: { type: ['string', 'array'] },
|
||||
enableBestPracticeRules: { type: 'boolean' },
|
||||
enableBestPracticeHints: { type: 'boolean' },
|
||||
exclude: {
|
||||
items: { type: 'string' },
|
||||
type: 'array'
|
||||
|
@ -45,36 +45,36 @@ export default class ChiselRule {
|
|||
}
|
||||
}
|
||||
}],
|
||||
scope: RuleScope.site
|
||||
scope: HintScope.any
|
||||
};
|
||||
|
||||
|
||||
public constructor(context: RuleContext) {
|
||||
/** Configuration of the chisel rule. */
|
||||
public constructor(context: HintContext) {
|
||||
/** Configuration of the chisel hint. */
|
||||
let chiselConfig: IChiselOptions = {};
|
||||
|
||||
/** Table of overriden config properties. */
|
||||
const overrideLookUp: object = {
|
||||
dom: ['include', 'exclude'],
|
||||
selector: ['include', 'exclude'],
|
||||
testsToRun: ['enableBestPracticeRules']
|
||||
testsToRun: ['enableBestPracticeHints']
|
||||
};
|
||||
|
||||
/** Interface of a chisel violation. */
|
||||
interface IChiselViolation extends AxeRule, IChiselDecorations { }
|
||||
|
||||
/** Load rule configuration. */
|
||||
const loadRuleConfig = () => {
|
||||
if (!context.ruleOptions) {
|
||||
/** Load hint configuration. */
|
||||
const loadHintConfig = () => {
|
||||
if (!context.hintOptions) {
|
||||
return;
|
||||
}
|
||||
|
||||
chiselConfig = context.ruleOptions;
|
||||
chiselConfig = context.hintOptions;
|
||||
};
|
||||
|
||||
/** Generate the script to initiate the chisel scan in a page. */
|
||||
const generateScript = (): string => {
|
||||
// This is run in the page, not sonarwhal itself.
|
||||
// This is run in the page, not webhint itself.
|
||||
const script: string =
|
||||
`function runChiselScan() {
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
@ -170,7 +170,7 @@ export default class ChiselRule {
|
|||
await Promise.all(reportPromises);
|
||||
};
|
||||
|
||||
loadRuleConfig();
|
||||
loadHintConfig();
|
||||
|
||||
context.on('traverse::end', validate);
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
module.exports = { chisel: require('./hint') };
|
|
@ -1,9 +1,8 @@
|
|||
import { generateHTMLPage } from 'sonarwhal/dist/tests/helpers/misc';
|
||||
import { getRuleName } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
|
||||
import { IRuleTest } from 'sonarwhal/dist/tests/helpers/rule-test-type';
|
||||
import * as ruleRunner from 'sonarwhal/dist/tests/helpers/rule-runner';
|
||||
import generateHTMLPage from 'hint/dist/src/lib/utils/misc/generate-html-page';
|
||||
import { HintTest } from '@hint/utils-tests-helpers/dist/src/hint-test-type';
|
||||
import * as hintRunner from '@hint/utils-tests-helpers/dist/src/hint-runner';
|
||||
|
||||
const ruleName = getRuleName(__dirname);
|
||||
const hintName = 'chisel';
|
||||
|
||||
const html = {
|
||||
missingLang: `<!doctype html>
|
||||
|
@ -17,7 +16,7 @@ const html = {
|
|||
noProblems: generateHTMLPage()
|
||||
};
|
||||
|
||||
const tests: Array<IRuleTest> = [
|
||||
const tests: Array<HintTest> = [
|
||||
{
|
||||
name: `Page doesn't have any a11y problems and passes`,
|
||||
serverConfig: html.noProblems
|
||||
|
@ -29,7 +28,7 @@ const tests: Array<IRuleTest> = [
|
|||
}
|
||||
];
|
||||
|
||||
const testsWithCustomConfiguration: Array<IRuleTest> = [
|
||||
const testsWithCustomConfiguration: Array<HintTest> = [
|
||||
{
|
||||
name: `Page doesn't have any a11y problems and passes`,
|
||||
serverConfig: html.noProblems
|
||||
|
@ -40,7 +39,7 @@ const testsWithCustomConfiguration: Array<IRuleTest> = [
|
|||
}
|
||||
];
|
||||
|
||||
const testsWithOverridenConfiguration: Array<IRuleTest> = [
|
||||
const testsWithOverridenConfiguration: Array<HintTest> = [
|
||||
{
|
||||
name: `Page doesn't have any a11y problems and passes, but warns about the overriden config setting`,
|
||||
reports: [{ message: 'exclude is ignored when selector is set.' }],
|
||||
|
@ -53,10 +52,10 @@ const testsWithOverridenConfiguration: Array<IRuleTest> = [
|
|||
}
|
||||
];
|
||||
|
||||
ruleRunner.testRule(ruleName, tests);
|
||||
ruleRunner.testRule(ruleName, testsWithCustomConfiguration, { ruleOptions: { testsToRun: ['color-contrast'] } });
|
||||
ruleRunner.testRule(ruleName, testsWithOverridenConfiguration, {
|
||||
ruleOptions: {
|
||||
hintRunner.testHint(hintName, tests);
|
||||
hintRunner.testHint(hintName, testsWithCustomConfiguration, { hintOptions: { testsToRun: ['color-contrast'] } });
|
||||
hintRunner.testHint(hintName, testsWithOverridenConfiguration, {
|
||||
hintOptions: {
|
||||
exclude: ['html'],
|
||||
selector: 'html'
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
import { generateHTMLPage } from 'sonarwhal/dist/tests/helpers/misc';
|
||||
import { RuleTest } from 'sonarwhal/dist/tests/helpers/rule-test-type';
|
||||
import * as ruleRunner from 'sonarwhal/dist/tests/helpers/rule-runner';
|
||||
import generateHTMLPage from 'hint/dist/src/lib/utils/misc/generate-html-page';
|
||||
import { HintTest } from '@hint/utils-tests-helpers/dist/src/hint-test-type';
|
||||
import * as hintRunner from '@hint/utils-tests-helpers/dist/src/hint-runner';
|
||||
|
||||
const ruleName = 'chisel';
|
||||
const hintName = 'chisel';
|
||||
|
||||
const html = {
|
||||
missingLang: `<!doctype html>
|
||||
|
@ -16,7 +16,7 @@ const html = {
|
|||
noProblems: generateHTMLPage()
|
||||
};
|
||||
|
||||
const tests: Array<RuleTest> = [
|
||||
const tests: Array<HintTest> = [
|
||||
{
|
||||
name: `Page doesn't have any a11y problems and passes`,
|
||||
serverConfig: html.noProblems
|
||||
|
@ -28,7 +28,7 @@ const tests: Array<RuleTest> = [
|
|||
}
|
||||
];
|
||||
|
||||
const testsWithCustomConfiguration: Array<RuleTest> = [
|
||||
const testsWithCustomConfiguration: Array<HintTest> = [
|
||||
{
|
||||
name: `Page doesn't have any a11y problems and passes`,
|
||||
serverConfig: html.noProblems
|
||||
|
@ -39,7 +39,7 @@ const testsWithCustomConfiguration: Array<RuleTest> = [
|
|||
}
|
||||
];
|
||||
|
||||
const testsWithOverridenConfiguration: Array<RuleTest> = [
|
||||
const testsWithOverridenConfiguration: Array<HintTest> = [
|
||||
{
|
||||
name: `Page doesn't have any a11y problems and passes, but warns about the overriden config setting`,
|
||||
reports: [{ message: 'exclude is ignored when selector is set.' }],
|
||||
|
@ -52,10 +52,10 @@ const testsWithOverridenConfiguration: Array<RuleTest> = [
|
|||
}
|
||||
];
|
||||
|
||||
ruleRunner.testRule(ruleName, tests);
|
||||
ruleRunner.testRule(ruleName, testsWithCustomConfiguration, { ruleOptions: { testsToRun: ['color-contrast'] } });
|
||||
ruleRunner.testRule(ruleName, testsWithOverridenConfiguration, {
|
||||
ruleOptions: {
|
||||
hintRunner.testHint(hintName, tests);
|
||||
hintRunner.testHint(hintName, testsWithCustomConfiguration, { hintOptions: { testsToRun: ['color-contrast'] } });
|
||||
hintRunner.testHint(hintName, testsWithOverridenConfiguration, {
|
||||
hintOptions: {
|
||||
exclude: ['html'],
|
||||
selector: 'html'
|
||||
}
|
|
@ -8,8 +8,8 @@
|
|||
"formatters": "stylish",
|
||||
"ignoredUrls": [],
|
||||
"parsers": ["javascript"],
|
||||
"rulesTimeout": 120000,
|
||||
"rules": {
|
||||
"hintsTimeout": 120000,
|
||||
"hints": {
|
||||
"jsll/awa-init": "error",
|
||||
"jsll/script-included": "error",
|
||||
"jsll/validate-config": "error"
|
|
@ -1,18 +1,18 @@
|
|||
# jsll (`jsll`)
|
||||
|
||||
Validate the inclusion and initialization of the JSLL script via
|
||||
multiple related rules.
|
||||
multiple related hints.
|
||||
|
||||
## What does the rule check?
|
||||
## What does the hint check?
|
||||
|
||||
JSLL is the analytics library used by Microsoft. This package
|
||||
contains the following rules:
|
||||
contains the following hints:
|
||||
|
||||
* `jsll/script-included`
|
||||
* `jsll/awa-init`
|
||||
* `jsll/validate-config`
|
||||
|
||||
These rules test the following:
|
||||
These hints test the following:
|
||||
|
||||
* Whether or not the JSLL script has been included.
|
||||
* If the script is inlcuded in `<head>`.
|
||||
|
@ -28,7 +28,7 @@ These rules test the following:
|
|||
* Validate the required properties in `config`.
|
||||
* Validate Optional properties in `config`.
|
||||
|
||||
### Examples that **trigger** the rule
|
||||
### Examples that **trigger** the hint
|
||||
|
||||
The JSLL script was not included
|
||||
|
||||
|
@ -92,7 +92,7 @@ Invalid required/optional properties.
|
|||
</head>
|
||||
```
|
||||
|
||||
### Examples that **pass** the rule
|
||||
### Examples that **pass** the hint
|
||||
|
||||
```html
|
||||
<head>
|
||||
|
@ -117,7 +117,7 @@ Invalid required/optional properties.
|
|||
</head>
|
||||
```
|
||||
|
||||
### How the rule works
|
||||
### How the hint works
|
||||
|
||||
* `script-included` uses two variables `totalHeadScriptCount` and
|
||||
`jsllScriptCount` to keep track of the total number of script tags and the
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -12,12 +12,13 @@
|
|||
"timeout": "1m"
|
||||
},
|
||||
"dependencies": {
|
||||
"locale-code": "^1.1.1",
|
||||
"eslint": "^4.18.2"
|
||||
"eslint": "^4.18.2",
|
||||
"locale-code": "^1.1.1"
|
||||
},
|
||||
"description": "sonarwhal rule to validate Microsoft's JSLL usage.",
|
||||
"description": "webhint hint to validate Microsoft's JSLL usage.",
|
||||
"devDependencies": {
|
||||
"@sonarwhal/parser-javascript": "^2.0.0",
|
||||
"@hint/parser-javascript": "^1.0.1",
|
||||
"@hint/utils-tests-helpers": "^1.0.1",
|
||||
"@types/debug": "0.0.30",
|
||||
"@types/node": "^9.4.6",
|
||||
"async-retry": "^1.2.1",
|
||||
|
@ -34,7 +35,7 @@
|
|||
"nyc": "^11.4.1",
|
||||
"on-headers": "^1.0.1",
|
||||
"rimraf": "^2.6.2",
|
||||
"sonarwhal": "^1.0.0",
|
||||
"hint": "^3.4.0",
|
||||
"typescript": "^2.6.2",
|
||||
"typescript-eslint-parser": "^14.0.0"
|
||||
},
|
||||
|
@ -45,19 +46,19 @@
|
|||
"dist/src",
|
||||
"npm-shrinkwrap.json"
|
||||
],
|
||||
"homepage": "https://sonarwhal.com",
|
||||
"homepage": "https://webhint.io",
|
||||
"keywords": [
|
||||
"sonarwhal",
|
||||
"sonarwhal-rule",
|
||||
"webhint",
|
||||
"webhint-hint",
|
||||
"jsll",
|
||||
"jsll-rule"
|
||||
"jsll-hint"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"main": "dist/src/index.js",
|
||||
"name": "sonarwhal-rule-jsll",
|
||||
"name": "webhint-hint-jsll",
|
||||
"peerDependencies": {
|
||||
"sonarwhal": "^1.0.0",
|
||||
"@sonarwhal/parser-javascript": "^2.0.0"
|
||||
"hint": "^3.4.0",
|
||||
"@hint/parser-javascript": "^1.0.1"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run clean && npm-run-all build:*",
|
||||
|
@ -73,8 +74,8 @@
|
|||
"watch:assets": "npm run build:assets -- -w --no-initial",
|
||||
"watch:test": "ava --watch",
|
||||
"watch:ts": "npm run build:ts -- --watch",
|
||||
"sonarwhal": "node node_modules/sonarwhal/dist/src/bin/sonarwhal.js"
|
||||
"hint": "node node_modules/hint/dist/src/bin/hint.js"
|
||||
},
|
||||
"repository": "Microsoft/sonarwhal-rules-microsoft",
|
||||
"version": "1.0.1"
|
||||
"repository": "Microsoft/webhint-hints-microsoft",
|
||||
"version": "2.0.0"
|
||||
}
|
|
@ -2,12 +2,12 @@
|
|||
* @fileoverview Validate the use of `awa.init` to initialize the JSLL script.
|
||||
*/
|
||||
|
||||
import { Category } from 'sonarwhal/dist/src/lib/enums/category';
|
||||
import { RuleContext } from 'sonarwhal/dist/src/lib/rule-context';
|
||||
import { IRule, RuleMetadata, IAsyncHTMLElement, ElementFound } from 'sonarwhal/dist/src/lib/types';
|
||||
import { ScriptParse } from '@sonarwhal/parser-javascript/dist/src/ScriptParse';
|
||||
import { debug as d } from 'sonarwhal/dist/src/lib/utils/debug';
|
||||
import { RuleScope } from 'sonarwhal/dist/src/lib/enums/rulescope';
|
||||
import { Category } from 'hint/dist/src/lib/enums/category';
|
||||
import { HintContext } from 'hint/dist/src/lib/hint-context';
|
||||
import { IHint, HintMetadata, IAsyncHTMLElement, ElementFound } from 'hint/dist/src/lib/types';
|
||||
import { ScriptParse } from '@hint/parser-javascript/dist/src/types';
|
||||
import { debug as d } from 'hint/dist/src/lib/utils/debug';
|
||||
import { HintScope } from 'hint/dist/src/lib/enums/hintscope';
|
||||
|
||||
import { isPotentialInitScript, configIsDefined } from '../validator';
|
||||
import { isJsllDir, isInitCode } from '../utils';
|
||||
|
@ -22,18 +22,18 @@ const debug: debug.IDebugger = d(__filename);
|
|||
* ------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
export default class JsllAwaInitRule implements IRule {
|
||||
public static readonly meta: RuleMetadata = {
|
||||
export default class JsllAwaInitRule implements IHint {
|
||||
public static readonly meta: HintMetadata = {
|
||||
docs: {
|
||||
category: Category.other,
|
||||
description: `Validate the use of 'awa.init' to initialize the JSLL script.`
|
||||
},
|
||||
id: 'jsll/awa-init',
|
||||
schema: [],
|
||||
scope: RuleScope.any
|
||||
scope: HintScope.any
|
||||
}
|
||||
|
||||
public constructor(context: RuleContext) {
|
||||
public constructor(context: HintContext) {
|
||||
const linter = new Linter();
|
||||
|
||||
/** States available. */
|
||||
|
@ -177,6 +177,6 @@ export default class JsllAwaInitRule implements IRule {
|
|||
context.on('element::body', enterBody);
|
||||
context.on('element::head', enterHead);
|
||||
context.on('element::script', enterScript);
|
||||
context.on('parse::javascript', validateScript);
|
||||
context.on('parse::javascript::end', validateScript);
|
||||
}
|
||||
}
|
|
@ -1,13 +1,13 @@
|
|||
/**
|
||||
* @fileoverview This rule confirms that JSLL script is included in the page
|
||||
*/
|
||||
import { Category } from 'sonarwhal/dist/src/lib/enums/category';
|
||||
import { RuleContext } from 'sonarwhal/dist/src/lib/rule-context';
|
||||
import { IAsyncHTMLElement, IRule, ElementFound, Severity, RuleMetadata } from 'sonarwhal/dist/src/lib/types';
|
||||
import { normalizeString } from 'sonarwhal/dist/src/lib/utils/misc';
|
||||
import { Category } from 'hint/dist/src/lib/enums/category';
|
||||
import { HintContext } from 'hint/dist/src/lib/hint-context';
|
||||
import { IAsyncHTMLElement, IHint, ElementFound, Severity, HintMetadata } from 'hint/dist/src/lib/types';
|
||||
import normalizeString from 'hint/dist/src/lib/utils/misc/normalize-string';
|
||||
|
||||
import { isJsllDir } from '../utils';
|
||||
import { RuleScope } from 'sonarwhal/dist/src/lib/enums/rulescope';
|
||||
import { HintScope } from 'hint/dist/src/lib/enums/hintscope';
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------------------------------
|
||||
|
@ -15,18 +15,18 @@ import { RuleScope } from 'sonarwhal/dist/src/lib/enums/rulescope';
|
|||
* ------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
export default class JsllScriptIncludedRule implements IRule {
|
||||
public static readonly meta: RuleMetadata = {
|
||||
export default class JsllScriptIncludedRule implements IHint {
|
||||
public static readonly meta: HintMetadata = {
|
||||
docs: {
|
||||
category: Category.other,
|
||||
description: `This rule confirms that JSLL script is included in the head of the page`
|
||||
},
|
||||
id: 'jsll/script-included',
|
||||
schema: [],
|
||||
scope: RuleScope.any
|
||||
scope: HintScope.any
|
||||
}
|
||||
|
||||
public constructor(context: RuleContext) {
|
||||
public constructor(context: HintContext) {
|
||||
// Messages.
|
||||
const noScriptInHeadMsg: string = `No JSLL script was included in the <head> tag.`;
|
||||
const redundantScriptInHeadMsg: string = `More than one JSLL scripts were included in the <head> tag.`;
|
|
@ -1,5 +1,5 @@
|
|||
import { IAsyncHTMLElement } from 'sonarwhal/dist/src/lib/types';
|
||||
import { normalizeString } from 'sonarwhal/dist/src/lib/utils/misc';
|
||||
import { IAsyncHTMLElement } from 'hint/dist/src/lib/types';
|
||||
import normalizeString from 'hint/dist/src/lib/utils/misc/normalize-string';
|
||||
|
||||
const jsllDir = `az725175.vo.msecnd.net/scripts/jsll-`;
|
||||
|
|
@ -2,16 +2,15 @@
|
|||
* @fileoverview Validate the required config properties.
|
||||
*/
|
||||
|
||||
import { Category } from 'sonarwhal/dist/src/lib/enums/category';
|
||||
import { RuleContext } from 'sonarwhal/dist/src/lib/rule-context';
|
||||
import { IRule, ScanEnd, RuleMetadata } from 'sonarwhal/dist/src/lib/types';
|
||||
// import { ScriptParse } from 'sonarwhal/dist/src/lib/parsers/javascript/types';
|
||||
import { ScriptParse } from '@sonarwhal/parser-javascript/dist/src/scriptParse';
|
||||
import { debug as d } from 'sonarwhal/dist/src/lib/utils/debug';
|
||||
import { Category } from 'hint/dist/src/lib/enums/category';
|
||||
import { HintContext } from 'hint/dist/src/lib/hint-context';
|
||||
import { IHint, ScanEnd, HintMetadata } from 'hint/dist/src/lib/types';
|
||||
import { ScriptParse } from '@hint/parser-javascript/dist/src/types';
|
||||
import { debug as d } from 'hint/dist/src/lib/utils/debug';
|
||||
|
||||
import { isPotentialInitScript, validateNodeProps, configProps } from '../validator';
|
||||
import { isObject } from '../utils';
|
||||
import { RuleScope } from 'sonarwhal/dist/src/lib/enums/rulescope';
|
||||
import { HintScope } from 'hint/dist/src/lib/enums/hintscope';
|
||||
|
||||
const debug: debug.IDebugger = d(__filename);
|
||||
|
||||
|
@ -52,18 +51,18 @@ const generateScript = (callInitCode) => {
|
|||
};
|
||||
|
||||
|
||||
export default class JsllValidateConfigRule implements IRule {
|
||||
public static readonly meta: RuleMetadata = {
|
||||
export default class JsllValidateConfigRule implements IHint {
|
||||
public static readonly meta: HintMetadata = {
|
||||
docs: {
|
||||
category: Category.other,
|
||||
description: `Validate the required config properties.`
|
||||
},
|
||||
id: 'jsll/validate-config',
|
||||
schema: [],
|
||||
scope: RuleScope.any
|
||||
scope: HintScope.any
|
||||
}
|
||||
|
||||
public constructor(context: RuleContext) {
|
||||
public constructor(context: HintContext) {
|
||||
/** Cache for the init code. */
|
||||
let script = '';
|
||||
/** Cache for the init code resource. */
|
||||
|
@ -137,7 +136,7 @@ export default class JsllValidateConfigRule implements IRule {
|
|||
});
|
||||
};
|
||||
|
||||
context.on('parse::javascript', populateScript);
|
||||
context.on('parse::javascript::end', populateScript);
|
||||
context.on('scan::end', evaluate);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
/**
|
||||
* @fileoverview jsll the initialization of the JSLL script.
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
'awa-init': require('./hints/awa-init/awa-init'),
|
||||
'script-included': require('./hints/script-included/script-included'),
|
||||
'validate-config': require('./hints/validate-config/validate-config')
|
||||
};
|
|
@ -1,10 +1,10 @@
|
|||
import { generateHTMLPage } from 'sonarwhal/dist/tests/helpers/misc';
|
||||
import { RuleTest } from 'sonarwhal/dist/tests/helpers/rule-test-type';
|
||||
import * as ruleRunner from 'sonarwhal/dist/tests/helpers/rule-runner';
|
||||
import generateHTMLPage from 'hint/dist/src/lib/utils/misc/generate-html-page';
|
||||
import { HintTest } from '@hint/utils-tests-helpers/dist/src/hint-test-type';
|
||||
import * as hintRunner from '@hint/utils-tests-helpers/dist/src/hint-runner';
|
||||
|
||||
import { code, scriptWrapper } from '../helpers/common';
|
||||
|
||||
const ruleName = 'jsll/awa-init';
|
||||
const hintName = 'jsll/awa-init';
|
||||
const messages = {
|
||||
noInit: `JSLL is not initialized with "awa.init(config)" function in <head>. Initialization script should be placed immediately after JSLL script.`,
|
||||
notCallASAP: `"awa.init" is not called as soon as possible.`,
|
||||
|
@ -13,7 +13,7 @@ const messages = {
|
|||
undefinedConfig: `The variable passed to "awa.init" is not defined.`
|
||||
};
|
||||
|
||||
const tests: Array<RuleTest> = [
|
||||
const tests: Array<HintTest> = [
|
||||
{
|
||||
// Validate init should still run even if the JSLL script link is not included.
|
||||
name: `The JSLL script itself was not included`,
|
||||
|
@ -81,4 +81,4 @@ const tests: Array<RuleTest> = [
|
|||
}
|
||||
];
|
||||
|
||||
ruleRunner.testRule(ruleName, tests, { parsers: ['javascript'] });
|
||||
hintRunner.testHint(hintName, tests, { parsers: ['javascript'] });
|
|
@ -1,8 +1,8 @@
|
|||
import { generateHTMLPage } from 'sonarwhal/dist/tests/helpers/misc';
|
||||
import { RuleTest } from 'sonarwhal/dist/tests/helpers/rule-test-type';
|
||||
import * as ruleRunner from 'sonarwhal/dist/tests/helpers/rule-runner';
|
||||
import generateHTMLPage from 'hint/dist/src/lib/utils/misc/generate-html-page';
|
||||
import { HintTest } from '@hint/utils-tests-helpers/dist/src/hint-test-type';
|
||||
import * as hintRunner from '@hint/utils-tests-helpers/dist/src/hint-runner';
|
||||
|
||||
const ruleName = 'jsll/script-included';
|
||||
const hintName = 'jsll/script-included';
|
||||
const baseUrl: string = `https://az725175.vo.msecnd.net/scripts/jsll`;
|
||||
const simpleVersionLink: string = `${baseUrl}-4.js`;
|
||||
const specifiedVersionLink: string = `${baseUrl}-4.2.1.js`;
|
||||
|
@ -28,7 +28,7 @@ const warningScriptVersionMsg = `Use the latest release of JSLL with 'jsll-4.js'
|
|||
const invalidScriptVersionMsg = `The jsll script versioning is not valid.`;
|
||||
const wrongScriptOrderMsg = `The JSLL script isn't placed prior to other scripts.`;
|
||||
|
||||
const tests: Array<RuleTest> = [
|
||||
const tests: Array<HintTest> = [
|
||||
{
|
||||
name: 'JSLL script locates in the <head> tag and has the recommended version format',
|
||||
serverConfig: generateHTMLPage(generateScript(simpleVersionLink))
|
||||
|
@ -64,4 +64,4 @@ const tests: Array<RuleTest> = [
|
|||
}
|
||||
];
|
||||
|
||||
ruleRunner.testRule(ruleName, tests);
|
||||
hintRunner.testHint(hintName, tests);
|
|
@ -1,10 +1,10 @@
|
|||
import { generateHTMLPage } from 'sonarwhal/dist/tests/helpers/misc';
|
||||
import { RuleTest } from 'sonarwhal/dist/tests/helpers/rule-test-type';
|
||||
import * as ruleRunner from 'sonarwhal/dist/tests/helpers/rule-runner';
|
||||
import generateHTMLPage from 'hint/dist/src/lib/utils/misc/generate-html-page';
|
||||
import { HintTest } from '@hint/utils-tests-helpers/dist/src/hint-test-type';
|
||||
import * as hintRunner from '@hint/utils-tests-helpers/dist/src/hint-runner';
|
||||
|
||||
import { code, deleteProp, modifyConfigVal, scriptWrapper } from '../helpers/common';
|
||||
|
||||
const ruleName = 'jsll/validate-config';
|
||||
const hintName = 'jsll/validate-config';
|
||||
const messages = {
|
||||
invalidAppId: `The "appId" must be a non-empty string.`,
|
||||
invalidAutoCapture: `The "autoCapture" property is not a valid object.`,
|
||||
|
@ -38,7 +38,7 @@ const stringPropertyConfig = {
|
|||
useShortNameForContentBlob: true
|
||||
};
|
||||
|
||||
const tests: Array<RuleTest> = [
|
||||
const tests: Array<HintTest> = [
|
||||
{
|
||||
name: `The JSLL script was not included, but the init script is present and the config is valid`,
|
||||
serverConfig: generateHTMLPage(`${scriptWrapper(`var config=${JSON.stringify(code.perfectConfig)};`, code.initConfig, false)}`)
|
||||
|
@ -151,4 +151,4 @@ const tests: Array<RuleTest> = [
|
|||
}
|
||||
];
|
||||
|
||||
ruleRunner.testRule(ruleName, tests, { parsers: ['javascript'] });
|
||||
hintRunner.testHint(hintName, tests, { parsers: ['javascript'] });
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1 +0,0 @@
|
|||
module.exports = { chisel: require('./rule') };
|
|
@ -1 +0,0 @@
|
|||
{"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\CHANGELOG.md":{"size":32,"mtime":1520713992111,"hashOfConfig":"1h35see","results":{"filePath":"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\CHANGELOG.md","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\README.md":{"size":4750,"mtime":1520714799802,"hashOfConfig":"1h35see","results":{"filePath":"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\README.md","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\src\\index.ts":{"size":295,"mtime":1520713992153,"hashOfConfig":"1h35see","results":{"filePath":"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\src\\index.ts","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\src\\rules\\awa-init\\awa-init.ts":{"size":7027,"mtime":1520713992166,"hashOfConfig":"1h35see","results":{"filePath":"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\src\\rules\\awa-init\\awa-init.ts","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\src\\rules\\script-included\\script-included.ts":{"size":4100,"mtime":1520713992174,"hashOfConfig":"1h35see","results":{"filePath":"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\src\\rules\\script-included\\script-included.ts","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\src\\rules\\utils.ts":{"size":2358,"mtime":1517938907986,"hashOfConfig":"1h35see","results":{"filePath":"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\src\\rules\\utils.ts","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\src\\rules\\validate-config\\validate-config.ts":{"size":4750,"mtime":1520713992186,"hashOfConfig":"1h35see","results":{"filePath":"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\src\\rules\\validate-config\\validate-config.ts","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\src\\rules\\validator.ts":{"size":6087,"mtime":1520713992190,"hashOfConfig":"1h35see","results":{"filePath":"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\src\\rules\\validator.ts","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\tests\\awa-init\\test.ts":{"size":4269,"mtime":1520713992190,"hashOfConfig":"1h35see","results":{"filePath":"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\tests\\awa-init\\test.ts","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\tests\\helpers\\common.ts":{"size":3175,"mtime":1517942583261,"hashOfConfig":"1h35see","results":{"filePath":"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\tests\\helpers\\common.ts","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\tests\\script-included\\test.ts":{"size":3022,"mtime":1520713992206,"hashOfConfig":"1h35see","results":{"filePath":"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\tests\\script-included\\test.ts","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\tests\\validate-config\\test.ts":{"size":7774,"mtime":1520713992206,"hashOfConfig":"1h35see","results":{"filePath":"C:\\projects\\Microsoft\\sonarwhal-rules-microsoft\\rules\\jsll\\tests\\validate-config\\test.ts","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}}}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,9 +0,0 @@
|
|||
/**
|
||||
* @fileoverview jsll the initialization of the JSLL script.
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
'awa-init': require('./rules/awa-init/awa-init'),
|
||||
'script-included': require('./rules/script-included/script-included'),
|
||||
'validate-config': require('./rules/validate-config/validate-config')
|
||||
};
|
Загрузка…
Ссылка в новой задаче