Skip to content

Commit 0328359

Browse files
author
Ethan Cohen
committed
Initial commit.
0 parents  commit 0328359

File tree

11 files changed

+394
-0
lines changed

11 files changed

+394
-0
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/**
2+
reports/**

.eslintrc

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
{
2+
"env": {
3+
"node": true
4+
},
5+
"ecmaFeatures": {
6+
jsx: true
7+
},
8+
"globals": {
9+
},
10+
"plugins": [
11+
],
12+
"rules": {
13+
// Possible Errors
14+
"comma-dangle": [2, "never"],
15+
"no-cond-assign": 2,
16+
"no-console": 1,
17+
"no-constant-condition": 2,
18+
"no-control-regex": 2,
19+
"no-debugger": 2,
20+
"no-dupe-keys": 2,
21+
"no-empty": 2,
22+
"no-empty-character-class": 2,
23+
"no-ex-assign": 2,
24+
"no-extra-boolean-cast": 2,
25+
"no-extra-parens": 0,
26+
"no-extra-semi": 2,
27+
"no-func-assign": 2,
28+
"no-inner-declarations": 2,
29+
"no-invalid-regexp": 2,
30+
"no-irregular-whitespace": 2,
31+
"no-negated-in-lhs": 2,
32+
"no-obj-calls": 2,
33+
"no-regex-spaces": 2,
34+
"no-reserved-keys": 0,
35+
"no-sparse-arrays": 2,
36+
"no-unreachable": 2,
37+
"use-isnan": 2,
38+
"valid-jsdoc": 0,
39+
"valid-typeof": 2,
40+
// Best Practices
41+
"block-scoped-var": 2,
42+
"complexity": 0,
43+
"consistent-return": 2,
44+
"curly": 2,
45+
"default-case": 2,
46+
"dot-notation": 2,
47+
"eqeqeq": 2,
48+
"guard-for-in": 2,
49+
"no-alert": 2,
50+
"no-caller": 2,
51+
"no-div-regex": 2,
52+
"no-else-return": 2,
53+
"no-eq-null": 2,
54+
"no-eval": 2,
55+
"no-extend-native": 2,
56+
"no-extra-bind": 2,
57+
"no-fallthrough": 2,
58+
"no-floating-decimal": 2,
59+
"no-implied-eval": 2,
60+
"no-iterator": 2,
61+
"no-labels": 2,
62+
"no-lone-blocks": 2,
63+
"no-loop-func": 2,
64+
"no-multi-spaces": 2,
65+
"no-multi-str": 0,
66+
"no-native-reassign": 2,
67+
"no-new": 2,
68+
"no-new-func": 2,
69+
"no-new-wrappers": 2,
70+
"no-octal": 2,
71+
"no-octal-escape": 2,
72+
"no-process-env": 2,
73+
"no-proto": 2,
74+
"no-redeclare": 2,
75+
"no-return-assign": 2,
76+
"no-script-url": 2,
77+
"no-self-compare": 2,
78+
"no-sequences": 2,
79+
"no-unused-expressions": 2,
80+
"no-void": 0,
81+
"no-warning-comments": 2,
82+
"no-with": 2,
83+
"radix": 2,
84+
"vars-on-top": 0,
85+
"wrap-iife": 2,
86+
"yoda": 2,
87+
// Strict Mode
88+
"strict": [2, "global"],
89+
// Variables
90+
"no-catch-shadow": 2,
91+
"no-delete-var": 2,
92+
"no-label-var": 2,
93+
"no-shadow": 2,
94+
"no-shadow-restricted-names": 2,
95+
"no-undef": 2,
96+
"no-undef-init": 2,
97+
"no-undefined": 2,
98+
"no-unused-vars": 2,
99+
"no-use-before-define": 2,
100+
// Stylistic Issues
101+
"indent": [2, 2, {
102+
"SwitchCase": 1
103+
}],
104+
"brace-style": 2,
105+
"camelcase": 0,
106+
"comma-spacing": 2,
107+
"comma-style": 2,
108+
"consistent-this": 0,
109+
"eol-last": 2,
110+
"func-names": 0,
111+
"func-style": 0,
112+
"key-spacing": [2, {
113+
"beforeColon": false,
114+
"afterColon": true
115+
}],
116+
"max-nested-callbacks": 0,
117+
"new-cap": 2,
118+
"new-parens": 2,
119+
"no-array-constructor": 2,
120+
"no-inline-comments": 0,
121+
"no-lonely-if": 2,
122+
"no-mixed-spaces-and-tabs": 2,
123+
"no-nested-ternary": 2,
124+
"no-new-object": 2,
125+
"semi-spacing": [2, {
126+
"before": false,
127+
"after": true
128+
}],
129+
"no-spaced-func": 2,
130+
"no-ternary": 0,
131+
"no-trailing-spaces": 2,
132+
"no-multiple-empty-lines": 2,
133+
"no-underscore-dangle": 0,
134+
"one-var": 0,
135+
"operator-assignment": [2, "always"],
136+
"padded-blocks": 0,
137+
"quotes": [2, "single"],
138+
"quote-props": [2, "as-needed"],
139+
"semi": [2, "always"],
140+
"sort-vars": [2, {"ignoreCase": true}],
141+
"keyword-spacing": 2,
142+
"space-before-blocks": 2,
143+
"object-curly-spacing": [2, "never"],
144+
"array-bracket-spacing": [2, "never"],
145+
"space-in-parens": 2,
146+
"space-infix-ops": 2,
147+
"space-unary-ops": 2,
148+
"spaced-comment": 2,
149+
"wrap-regex": 0,
150+
// Legacy
151+
"max-depth": 0,
152+
"max-len": [2, 120],
153+
"max-params": 0,
154+
"max-statements": 0,
155+
"no-plusplus": 0
156+
}
157+
}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
reports
3+
npm-debug.log
4+
coverage

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
language: node_js
2+
node_js:
3+
- 0.10
4+
- 0.12
5+
- iojs
6+
- 4
7+
- 5
8+
after_success:
9+
- npm run coveralls

LICENSE.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The MIT License (MIT)
2+
Copyright (c) 2016 Ethan Cohen
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
6+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
8+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# eslint-plugin-jsx-a11y
2+
3+
A static analysis linter of React components and their accessibility with screen readers.
4+
5+
## Installation
6+
7+
You'll first need to install [ESLint](http://eslint.org):
8+
9+
```
10+
$ npm i eslint --save-dev
11+
```
12+
13+
Next, install `eslint-plugin-jsx-a11y`:
14+
15+
```
16+
$ npm install eslint-plugin-jsx-a11y --save-dev
17+
```
18+
19+
**Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `eslint-plugin-jsx-a11y` globally.
20+
21+
## Usage
22+
23+
Add `jsx-a11y` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
24+
25+
```json
26+
{
27+
"plugins": [
28+
"jsx-a11y"
29+
]
30+
}
31+
```
32+
33+
34+
Then configure the rules you want to use under the rules section.
35+
36+
```json
37+
{
38+
"rules": {
39+
"jsx-a11y/rule-name": 2
40+
}
41+
}
42+
```
43+
44+
## Supported Rules
45+
46+
* Fill in provided rules here
47+
48+
49+
50+
51+

index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
module.exports = {
4+
rules: {
5+
'img-uses-alt': require('./lib/rules/img-uses-alt')
6+
},
7+
configs: {
8+
recommended: {
9+
parserOptions: {
10+
ecmaFeatures: {
11+
jsx: true
12+
}
13+
}
14+
}
15+
}
16+
};

lib/rules/img-uses-alt.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @fileoverview Enforce img tag uses alt attribute.
3+
* @author Ethan Cohen
4+
*/
5+
'use strict';
6+
7+
// ------------------------------------------------------------------------------
8+
// Rule Definition
9+
// ------------------------------------------------------------------------------
10+
11+
// function containsAlt(attribute) {
12+
13+
// };
14+
15+
module.exports = function(context) {
16+
17+
// var configuration = context.options[0] || {};
18+
19+
return {
20+
JSXOpeningElement: function(node) {
21+
var hasAltProp = node.attributes.some(function(attribute, idx, attrs) {
22+
// If the only attribute is a spread attribute, then pass rule.
23+
if (attribute.type === 'JSXSpreadAttribute' && attrs.length === 1) {
24+
return true;
25+
} else if (attribute.type === 'JSXSpreadAttribute') {
26+
return false;
27+
}
28+
29+
return attribute.name.name.toUpperCase() === 'ALT';
30+
});
31+
32+
if (!hasAltProp) {
33+
context.report({
34+
node: node,
35+
message: 'IMG element must have alt tag.'
36+
});
37+
}
38+
}
39+
};
40+
};
41+
42+
module.exports.schema = [{
43+
type: 'object'
44+
}];

package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "eslint-plugin-jsx-a11y",
3+
"version": "0.0.1",
4+
"description": "A static analysis linter of jsx and their accessibility with screen readers.",
5+
"keywords": [
6+
"eslint",
7+
"eslintplugin",
8+
"eslint-plugin"
9+
],
10+
"author": "Ethan Cohen",
11+
"main": "lib/index.js",
12+
"scripts": {
13+
"coveralls": "cat ./reports/coverage/lcov.info | coveralls",
14+
"lint": "eslint ./",
15+
"test": "npm run lint && npm run unit-test",
16+
"unit-test": "istanbul cover --dir reports/coverage node_modules/mocha/bin/_mocha tests/**/*.js -- --reporter dot"
17+
},
18+
"devDependencies": {
19+
"babel-eslint": "5.0.0-beta10",
20+
"coveralls": "2.11.6",
21+
"eslint": "2.1.0",
22+
"istanbul": "0.4.2",
23+
"mocha": "2.4.5"
24+
},
25+
"engines": {
26+
"node": ">=0.10.0"
27+
},
28+
"license": "MIT"
29+
}

tests/index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* eslint-env mocha */
2+
'use strict';
3+
4+
var plugin = require('..');
5+
6+
var assert = require('assert');
7+
var fs = require('fs');
8+
var path = require('path');
9+
10+
var rules = fs.readdirSync(path.resolve(__dirname, '../lib/rules/'))
11+
.map(function(f) {
12+
return path.basename(f, '.js');
13+
});
14+
15+
describe('all rule files should be exported by the plugin', function() {
16+
rules.forEach(function(ruleName) {
17+
it('should export ' + ruleName, function() {
18+
assert.equal(
19+
plugin.rules[ruleName],
20+
require(path.join('../lib/rules', ruleName))
21+
);
22+
});
23+
});
24+
});
25+
26+
// describe('configurations', function() {
27+
// it('should export a \'recommended\' configuration', function() {
28+
// assert(plugin.configs.recommended);
29+
// });
30+
// });

0 commit comments

Comments
 (0)