Socket
Socket
Sign inDemoInstall

access-sniff

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

access-sniff - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

.jscsrc

6

Gruntfile.js

@@ -30,3 +30,7 @@ module.exports = function(grunt) {

jscs: {
main: [ "src/*.js" ]
},
// Uglify

@@ -91,3 +95,3 @@ // ------------------------

grunt.registerTask('test', ['clean:tests', 'exec', 'jshint', 'nodeunit']);
grunt.registerTask('test', ['clean:tests', 'uglify:dev', 'exec', 'nodeunit', 'jshint', 'jscs']);

@@ -94,0 +98,0 @@

3

package.json
{
"name": "access-sniff",
"version": "0.1.1",
"version": "0.1.2",
"description": "A node/iojs library & CLI for HTML_Codesniffer",

@@ -30,2 +30,3 @@ "main": "src/accessSniff.js",

"grunt-exec": "^0.4.6",
"grunt-jscs": "^1.5.0",
"load-grunt-tasks": "^3.1.0",

@@ -32,0 +33,0 @@ "time-grunt": "^1.1.0"

@@ -6,17 +6,136 @@ # AccessSniff

![Example Image](img/example.png)
NOTE: This is in beta, please leave feedback. Would love it :)
## Getting Started
Install this plugin with `npm install access-sniff`
Install this plugin with `npm install access-sniff` then use it in your project with
then use it in your project with
```javascript
var accessSniff = require('access-sniff');
var files = ['**/*.html'];
accessSniff.start(files, options);
```
or install the module globally and type
```
sniff test/**/*.html -r json -l reports
```
## Options
You can pass some options
### Accessibility Level
```accessibilityLevel``` is a string
```javascript
var sniff = require('accessSniff');
options: {
accessibilityLevel: 'WCAG2A'
}
```
Levels are ```WCAG2A```, ```WCAG2AA```, and ```WCAG2AAA```
### Accessibilityrc
```accessibilityrc``` is a boolean
```javascript
options: {
accessibilityrc: true
}
```
Set to true to access a .accessibilityrc file in your project which should be layed out as:
```javascript
{
"ignore": [
"WCAG2A.Principle2.Guideline2_4.2_4_2.H25.1.NoTitleEl",
"WCAG2A.Principle3.Guideline3_1.3_1_1.H57.2"
]
}
```
### Ignore
```ignore``` is a array
You can ignore rules by placing them in an array outlined below
```javascript
ignore : [
'WCAG2A.Principle2.Guideline2_4.2_4_2.H25.1.NoTitleEl'
'WCAG2A.Principle3.Guideline3_1.3_1_1.H57.2'
]
```
### Output Format
```outputFormat``` is a string
```javascript
options: {
outputFormat: 'json'
}
```
Text or JSON format output
- 'txt' will output text files
- 'json' will output .json files
### Verbose output
```verbose``` is a boolean
```javascript
options: {
verbose: false
}
```
Output messages to console, set to true by default
### DomElement
``` domElement ``` is a boolean
```javascript
options: {
domElement: false
}
```
Include reference (tag name, class names & id) to reported elements. Optional for both output formats.
### Force
```force``` is a boolean
```javascript
options: {
force: true
}
```
Continue running grunt in the event of failures
## CLI
You can use the CLI component by installing it globally with `npm install -g access-sniff`
```cmd
sniff test/**/*.html -r json -l reports
sniff test/**/*.html -r csv -l reports
sniff test/**/*.html -r txt -l reports
```
### Options

@@ -23,0 +142,0 @@

@@ -50,3 +50,2 @@ /*

accessibilityrc: false,
reportType: null,

@@ -56,3 +55,2 @@ reportLocation : 'reports'

/**

@@ -63,3 +61,2 @@ * The Message Terminal, choo choo

*/
Accessibility.prototype.terminalLog = function(msg, trace) {

@@ -70,5 +67,6 @@

var options = _that.options;
var message = {};
// If ignore get the hell out
_.each(options.ignore, function (value, key) {
_.each(options.ignore, function(value, key) {
if (value === msgSplit[1]) {

@@ -83,12 +81,15 @@ ignore = true;

var message = {};
// Start the Logging
if (msgSplit[0] === 'ERROR' || msgSplit[0] === 'NOTICE' || msgSplit[0] === 'WARNING') {
var element = {
node: msgSplit[3],
class: msgSplit[4],
id: msgSplit[5]
};
message = {
heading: msgSplit[0],
issue: msgSplit[1],
element: msgSplit[3],
element: element,
position: this.getElementPosition(msgSplit[3]),

@@ -118,4 +119,2 @@ description: msgSplit[2],

/**

@@ -126,10 +125,9 @@ * Get Elements Line and Column Number

*/
Accessibility.prototype.getElementPosition = function(htmlString) {
var position = {};
var htmlArray = this.fileContents.split("\n");
var htmlArray = this.fileContents.split('\n');
htmlArray.every(function(element, lineNumber) {
if ( !element.match(htmlString) ) {
if (!element.match(htmlString)) {
return true;

@@ -140,3 +138,2 @@ }

var colIndex = 0;
var pattern = /(\s|\t)/g;

@@ -160,11 +157,8 @@

Accessibility.prototype.parseOutput = function(file, deferred) {
var test = file.split("\n");
var test = file.split('\n');
var _this = this;
var messageLog = [];
var messageLog = [];
test.every(function(element, index, array) {

@@ -198,3 +192,2 @@

/**

@@ -208,5 +201,4 @@ * Run task

*/
Accessibility.prototype.run = function(filesInput, callback) {
Accessibility.prototype.run = function(filesInput) {
var files = Promise.resolve(filesInput);

@@ -247,4 +239,3 @@ var _this = this;

fs.readFile(file, 'utf8', function (err, data) {
fs.readFile(file, 'utf8', function(err, data) {
_this.fileContents = data.toString();

@@ -258,18 +249,25 @@ });

console.error(err);
return err;
})
.finally();
.finally(function() {
if (typeof callback === 'function') {
callback();
}
return true;
});
};
Accessibility.start = function(files, options) {
Accessibility.start = function(files, options, callback) {
var task = new Accessibility(options);
task.run(files);
return task.run(files, callback);
};
module.exports = Accessibility;

@@ -5,3 +5,2 @@ var program = require('commander');

var exports = {};

@@ -21,2 +20,6 @@

if (!program.args.length) {
console.error('Please provide a filepath to check');
return false;
}

@@ -23,0 +26,0 @@ // ADD IN REPORTS

@@ -11,9 +11,8 @@ var chalk = require('chalk');

heading = chalk.red.bold(message.heading);
break;
break;
case 'NOTICE':
heading = chalk.blue.bold(message.heading);
break;
break;
default:
heading = chalk.yellow.bold(message.heading);
break;
}

@@ -27,3 +26,3 @@

console.log(chalk.grey('--------------------'));
console.log(chalk.grey(message.element));
console.log(chalk.grey(message.element.node));
console.log('');

@@ -49,4 +48,2 @@

module.exports = logger;

@@ -14,7 +14,5 @@ 'use strict';

// Messages are sent to the parent by appending them to the tempfile.
// NOTE, the tempfile appears to be shared between asynchronously running grunt tasks
var sendMessage = function (arg) {
var sendMessage = function(arg) {
var args = Array.isArray(arg) ? arg : [].slice.call(arguments);

@@ -31,7 +29,7 @@ var channel = args[0];

// Create a new page.
// --------------------
// Relay console logging messages.
page.onConsoleMessage = function(message) {
// // Relay console logging messages.
page.onConsoleMessage = function (message) {
if (message === 'done') {

@@ -45,3 +43,3 @@ sendMessage('wcaglint.done', options);

page.onError = function (msg, trace) {
page.onError = function(msg, trace) {
sendMessage('error', msg, trace);

@@ -55,8 +53,6 @@ };

page.onLoadFinished = function(status) {
sendMessage('console', 'Page Loaded. Starting Tests');
};
page.open(url, function (status) {
page.open(url, function(status) {

@@ -71,18 +67,17 @@ page.injectJs('../libs/dist/HTMLCS.min.js');

page.evaluate(function() {
HTMLCS_RUNNER.run('WCAG2A');
HTMLCS_RUNNER.run('WCAG2A');
});
break;
break;
case 'WCAG2AA':
page.evaluate(function() {
HTMLCS_RUNNER.run('WCAG2AA');
HTMLCS_RUNNER.run('WCAG2AA');
});
break;
break;
case 'WCAG2AAA':
page.evaluate(function() {
HTMLCS_RUNNER.run('WCAG2AAA');
HTMLCS_RUNNER.run('WCAG2AAA');
});
break;
break;
default:
console.log('Unknown standard.');
break;
}

@@ -89,0 +84,0 @@

@@ -11,3 +11,3 @@ var fs = require('fs');

switch(options.reportType) {
switch (options.reportType) {

@@ -36,3 +36,2 @@ case 'json':

reports.reportJson = function(messageLog) {

@@ -45,3 +44,2 @@

reports.reportTxt = function(messageLog) {

@@ -56,3 +54,5 @@

output += message.issue + seperator;
output += message.element + seperator;
output += message.element.node + seperator;
output += message.element.id + seperator;
output += message.element.class + seperator;
output += message.position.lineNumber + seperator;

@@ -68,3 +68,2 @@ output += message.position.columnNumber + seperator;

reports.reportCsv = function(messageLog) {

@@ -79,3 +78,5 @@

output += '"' + message.issue + '"' + seperator;
output += message.element + seperator;
output += message.element.node + seperator;
output += message.element.id + seperator;
output += message.element.class + seperator;
output += message.position.lineNumber + seperator;

@@ -99,3 +100,3 @@ output += message.position.columnNumber + seperator;

var filePath = '/'+ reportLocation + '/' + reportName + '.' + reportType;
var filePath = '/' + reportLocation + '/' + reportName + '.' + reportType;

@@ -113,5 +114,4 @@ fs.writeFile(process.cwd() + filePath, reportOutput, function(err) {

};
module.exports = reports;
function Runner() {
this.run = function(standard) {
var self = this;
var _this = this;
// At the moment, it passes the whole DOM document.
HTMLCS.process(standard, document, function() {
var messages = HTMLCS.getMessages();
var length = messages.length;
// At the moment, it passes the whole DOM document.
HTMLCS.process(standard, document, function() {
var messages = HTMLCS.getMessages();
for (var i = 0; i < length; i++) {
messages.forEach(function(message, index, array) {
// Print out actual element to string
message.elementString = message.element.outerHTML;
var htmlString = messages[i].element.outerHTML;
// Output to messages
_this.output(message);
});
// Print out actual element to string
messages[i].elementString = htmlString;
console.log('done');
});
};
// Output to messages
self.output(messages[i]);
}
this.output = function(msg) {
// Simple output for now.
var typeName = 'UNKNOWN';
console.log('done');
});
};
switch (msg.type) {
case HTMLCS.ERROR:
typeName = 'ERROR';
break;
this.output = function(msg) {
// Simple output for now.
var typeName = 'UNKNOWN';
case HTMLCS.WARNING:
typeName = 'WARNING';
break;
console.log(msg);
case HTMLCS.NOTICE:
typeName = 'NOTICE';
break;
}
switch (msg.type) {
case HTMLCS.ERROR:
typeName = 'ERROR';
break;
var message =
typeName + '|' +
msg.code + '|' +
msg.msg + '|' +
msg.elementString + '|' +
msg.element.className + '|' +
msg.element.id;
case HTMLCS.WARNING:
typeName = 'WARNING';
break;
console.log(message);
case HTMLCS.NOTICE:
typeName = 'NOTICE';
break;
}
};
console.log(
typeName + '|' +
msg.code + '|' +
msg.msg + '|' +
msg.elementString + '|' +
msg.element.className + '|' +
msg.element.id
);
};
}
var HTMLCS_RUNNER = new Runner();

@@ -1,1 +0,1 @@

[{"heading":"NOTICE","issue":"WCAG2A.Principle2.Guideline2_4.2_4_2.H25.2","element":"<title>Test One</title>","position":{"lineNumber":3,"columnNumber":4},"description":"Check that the title element describes the document."},{"heading":"ERROR","issue":"WCAG2A.Principle3.Guideline3_1.3_1_1.H57.2","element":"<html><head>\n <title>Test One</title>\n </head>\n <body>\n <h1>Derp</h1>\n <a id=\"herpDerp\" class=\"test Element\" href=\"test\">Test</a>\n <a href=\"test\">Test</a>\n <a href=\"test\" class=\"herp\">Test</a>\n \n\n</body></html>","position":{},"description":"The html element should have a lang or xml:lang attribute which describes the language of the document."},{"heading":"NOTICE","issue":"WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81","element":"<a id=\"herpDerp\" class=\"test Element\" href=\"test\">Test</a>","position":{"lineNumber":7,"columnNumber":4},"description":"Check that the link text combined with programmatically determined link context identifies the purpose of the link."},{"heading":"NOTICE","issue":"WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81","element":"<a href=\"test\">Test</a>","position":{"lineNumber":8,"columnNumber":4},"description":"Check that the link text combined with programmatically determined link context identifies the purpose of the link."},{"heading":"NOTICE","issue":"WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81","element":"<a href=\"test\" class=\"herp\">Test</a>","position":{"lineNumber":9,"columnNumber":4},"description":"Check that the link text combined with programmatically determined link context identifies the purpose of the link."}]
[{"heading":"NOTICE","issue":"WCAG2A.Principle2.Guideline2_4.2_4_2.H25.2","element":{"node":"<title>Test One</title>","class":"","id":""},"position":{"lineNumber":3,"columnNumber":4},"description":"Check that the title element describes the document."},{"heading":"ERROR","issue":"WCAG2A.Principle3.Guideline3_1.3_1_1.H57.2","element":{"node":"<html><head>\n <title>Test One</title>\n </head>\n <body>\n <h1>Derp</h1>\n <a id=\"herpDerp\" class=\"test Element\" href=\"test\">Test</a>\n <a href=\"test\">Test</a>\n <a href=\"test\" class=\"herp\">Test</a>\n \n\n</body></html>","class":"","id":""},"position":{},"description":"The html element should have a lang or xml:lang attribute which describes the language of the document."},{"heading":"NOTICE","issue":"WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81","element":{"node":"<a id=\"herpDerp\" class=\"test Element\" href=\"test\">Test</a>","class":"test Element","id":"herpDerp"},"position":{"lineNumber":7,"columnNumber":4},"description":"Check that the link text combined with programmatically determined link context identifies the purpose of the link."},{"heading":"NOTICE","issue":"WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81","element":{"node":"<a href=\"test\">Test</a>","class":"","id":""},"position":{"lineNumber":8,"columnNumber":4},"description":"Check that the link text combined with programmatically determined link context identifies the purpose of the link."},{"heading":"NOTICE","issue":"WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81","element":{"node":"<a href=\"test\" class=\"herp\">Test</a>","class":"herp","id":""},"position":{"lineNumber":9,"columnNumber":4},"description":"Check that the link text combined with programmatically determined link context identifies the purpose of the link."}]
heading, issue, element, line, column, description
NOTICE|WCAG2A.Principle2.Guideline2_4.2_4_2.H25.2|<title>Test One</title>|3|4|Check that the title element describes the document.
NOTICE|WCAG2A.Principle2.Guideline2_4.2_4_2.H25.2|<title>Test One</title>|||3|4|Check that the title element describes the document.
ERROR|WCAG2A.Principle3.Guideline3_1.3_1_1.H57.2|<html><head>

@@ -13,5 +13,5 @@ <title>Test One</title>

</body></html>|undefined|undefined|The html element should have a lang or xml:lang attribute which describes the language of the document.
NOTICE|WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81|<a id="herpDerp" class="test Element" href="test">Test</a>|7|4|Check that the link text combined with programmatically determined link context identifies the purpose of the link.
NOTICE|WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81|<a href="test">Test</a>|8|4|Check that the link text combined with programmatically determined link context identifies the purpose of the link.
NOTICE|WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81|<a href="test" class="herp">Test</a>|9|4|Check that the link text combined with programmatically determined link context identifies the purpose of the link.
</body></html>|||undefined|undefined|The html element should have a lang or xml:lang attribute which describes the language of the document.
NOTICE|WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81|<a id="herpDerp" class="test Element" href="test">Test</a>|herpDerp|test Element|7|4|Check that the link text combined with programmatically determined link context identifies the purpose of the link.
NOTICE|WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81|<a href="test">Test</a>|||8|4|Check that the link text combined with programmatically determined link context identifies the purpose of the link.
NOTICE|WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81|<a href="test" class="herp">Test</a>||herp|9|4|Check that the link text combined with programmatically determined link context identifies the purpose of the link.

@@ -1,1 +0,1 @@

[{"heading":"NOTICE","issue":"WCAG2A.Principle2.Guideline2_4.2_4_2.H25.2","element":"<title>Test Two</title>","position":{"lineNumber":3,"columnNumber":4},"description":"Check that the title element describes the document."},{"heading":"ERROR","issue":"WCAG2A.Principle3.Guideline3_1.3_1_1.H57.2","element":"<html><head>\n <title>Test Two</title>\n </head>\n <body>\n <h1>Derp</h1>\n <a id=\"herpDerp\" class=\"test Element\" href=\"test\">Test</a>\n <a href=\"test\">Test</a>\n <a href=\"test\" class=\"herp\">Test</a>\n \n\n</body></html>","position":{},"description":"The html element should have a lang or xml:lang attribute which describes the language of the document."},{"heading":"NOTICE","issue":"WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81","element":"<a id=\"herpDerp\" class=\"test Element\" href=\"test\">Test</a>","position":{"lineNumber":7,"columnNumber":4},"description":"Check that the link text combined with programmatically determined link context identifies the purpose of the link."},{"heading":"NOTICE","issue":"WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81","element":"<a href=\"test\">Test</a>","position":{"lineNumber":8,"columnNumber":4},"description":"Check that the link text combined with programmatically determined link context identifies the purpose of the link."},{"heading":"NOTICE","issue":"WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81","element":"<a href=\"test\" class=\"herp\">Test</a>","position":{"lineNumber":9,"columnNumber":4},"description":"Check that the link text combined with programmatically determined link context identifies the purpose of the link."}]
[{"heading":"NOTICE","issue":"WCAG2A.Principle2.Guideline2_4.2_4_2.H25.2","element":{"node":"<title>Test Two</title>","class":"","id":""},"position":{"lineNumber":3,"columnNumber":4},"description":"Check that the title element describes the document."},{"heading":"ERROR","issue":"WCAG2A.Principle3.Guideline3_1.3_1_1.H57.2","element":{"node":"<html><head>\n <title>Test Two</title>\n </head>\n <body>\n <h1>Derp</h1>\n <a id=\"herpDerp\" class=\"test Element\" href=\"test\">Test</a>\n <a href=\"test\">Test</a>\n <a href=\"test\" class=\"herp\">Test</a>\n \n\n</body></html>","class":"","id":""},"position":{},"description":"The html element should have a lang or xml:lang attribute which describes the language of the document."},{"heading":"NOTICE","issue":"WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81","element":{"node":"<a id=\"herpDerp\" class=\"test Element\" href=\"test\">Test</a>","class":"test Element","id":"herpDerp"},"position":{"lineNumber":7,"columnNumber":4},"description":"Check that the link text combined with programmatically determined link context identifies the purpose of the link."},{"heading":"NOTICE","issue":"WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81","element":{"node":"<a href=\"test\">Test</a>","class":"","id":""},"position":{"lineNumber":8,"columnNumber":4},"description":"Check that the link text combined with programmatically determined link context identifies the purpose of the link."},{"heading":"NOTICE","issue":"WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81","element":{"node":"<a href=\"test\" class=\"herp\">Test</a>","class":"herp","id":""},"position":{"lineNumber":9,"columnNumber":4},"description":"Check that the link text combined with programmatically determined link context identifies the purpose of the link."}]
heading, issue, element, line, column, description
NOTICE|WCAG2A.Principle2.Guideline2_4.2_4_2.H25.2|<title>Test Two</title>|3|4|Check that the title element describes the document.
NOTICE|WCAG2A.Principle2.Guideline2_4.2_4_2.H25.2|<title>Test Two</title>|||3|4|Check that the title element describes the document.
ERROR|WCAG2A.Principle3.Guideline3_1.3_1_1.H57.2|<html><head>

@@ -13,5 +13,5 @@ <title>Test Two</title>

</body></html>|undefined|undefined|The html element should have a lang or xml:lang attribute which describes the language of the document.
NOTICE|WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81|<a id="herpDerp" class="test Element" href="test">Test</a>|7|4|Check that the link text combined with programmatically determined link context identifies the purpose of the link.
NOTICE|WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81|<a href="test">Test</a>|8|4|Check that the link text combined with programmatically determined link context identifies the purpose of the link.
NOTICE|WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81|<a href="test" class="herp">Test</a>|9|4|Check that the link text combined with programmatically determined link context identifies the purpose of the link.
</body></html>|||undefined|undefined|The html element should have a lang or xml:lang attribute which describes the language of the document.
NOTICE|WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81|<a id="herpDerp" class="test Element" href="test">Test</a>|herpDerp|test Element|7|4|Check that the link text combined with programmatically determined link context identifies the purpose of the link.
NOTICE|WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81|<a href="test">Test</a>|||8|4|Check that the link text combined with programmatically determined link context identifies the purpose of the link.
NOTICE|WCAG2A.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81|<a href="test" class="herp">Test</a>||herp|9|4|Check that the link text combined with programmatically determined link context identifies the purpose of the link.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc