Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,11 @@ rules in templates can be disabled with eslint directives with mustache or html

### Best Practices

| Name | Description | 💼 | 🔧 | 💡 |
| :--------------------------------------------------------- | :--------------------------------- | :- | :- | :- |
| [template-no-debugger](docs/rules/template-no-debugger.md) | disallow {{debugger}} in templates | | | |
| [template-no-log](docs/rules/template-no-log.md) | disallow {{log}} in templates | | | |
| Name                            | Description | 💼 | 🔧 | 💡 |
| :------------------------------------------------------------------------------- | :----------------------------------------------------------- | :- | :- | :- |
| [template-no-accesskey-attribute](docs/rules/template-no-accesskey-attribute.md) | disallow `accesskey` attribute on HTML elements in templates | | 🔧 | |
| [template-no-debugger](docs/rules/template-no-debugger.md) | disallow {{debugger}} in templates | | | |
| [template-no-log](docs/rules/template-no-log.md) | disallow {{log}} in templates | | | |

### Components

Expand Down
44 changes: 44 additions & 0 deletions docs/rules/template-no-accesskey-attribute.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ember/template-no-accesskey-attribute

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

<!-- end auto-generated rule header -->

Disallows the use of `accesskey` attribute on elements.

The `accesskey` attribute creates inconsistencies between keyboard shortcuts and keyboard commands used by screen readers and keyboard-only users, causing accessibility issues.

## Examples

Examples of **incorrect** code for this rule:

```gjs
<template>
<button accesskey="s">Save</button>
</template>
```

```gjs
<template>
<a href="#" accesskey="h">Home</a>
</template>
```

Examples of **correct** code for this rule:

```gjs
<template>
<button>Save</button>
</template>
```

```gjs
<template>
<a href="#">Home</a>
</template>
```

## References

- [ember-template-lint no-accesskey-attribute](https://github.com/ember-template-lint/ember-template-lint/blob/master/docs/rule/no-accesskey-attribute.md)
- [WebAIM: Keyboard Accessibility - Accesskey](https://webaim.org/techniques/keyboard/accesskey)
2 changes: 1 addition & 1 deletion lib/recommended-rules-gjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
* definitions, execute "npm run update"
*/
module.exports = {
'ember/template-no-let-reference': 'error',
"ember/template-no-let-reference": "error"
};
2 changes: 1 addition & 1 deletion lib/recommended-rules-gts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
* definitions, execute "npm run update"
*/
module.exports = {
'ember/template-no-let-reference': 'error',
"ember/template-no-let-reference": "error"
};
2 changes: 1 addition & 1 deletion lib/recommended-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ module.exports = {
"ember/routes-segments-snake-case": "error",
"ember/use-brace-expansion": "error",
"ember/use-ember-data-rfc-395-imports": "error"
}
};
54 changes: 54 additions & 0 deletions lib/rules/template-no-accesskey-attribute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'disallow `accesskey` attribute on HTML elements in templates',
category: 'Best Practices',
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-accesskey-attribute.md',
},
fixable: 'code',
schema: [],
messages: {
noAccesskey:
'No access key attribute allowed. Inconsistencies between keyboard shortcuts and keyboard comments used by screenreader and keyboard only users create a11y complications.',
},
},

create(context) {
const sourceCode = context.sourceCode;

return {
GlimmerElementNode(node) {
if (!node.attributes) {
return;
}

const accessKeyAttr = node.attributes.find(
(attr) =>
attr.type === 'GlimmerAttrNode' &&
attr.name &&
attr.name === 'accesskey'
);

if (accessKeyAttr) {
context.report({
node: accessKeyAttr,
messageId: 'noAccesskey',
fix(fixer) {
// Get the range of the attribute
const attrStart = accessKeyAttr.range[0];
const attrEnd = accessKeyAttr.range[1];

// Check if there's a space before the attribute that should be removed
const sourceText = sourceCode.getText();
const removeStart = attrStart > 0 && sourceText[attrStart - 1] === ' ' ? attrStart - 1 : attrStart;

return fixer.removeRange([removeStart, attrEnd]);
},
});
}
},
};
},
};
56 changes: 28 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,51 +60,51 @@
},
"dependencies": {
"@ember-data/rfc395-data": "^0.0.4",
"css-tree": "^3.0.1",
"ember-eslint-parser": "^0.5.9",
"css-tree": "^3.1.0",
"ember-eslint-parser": "^0.5.13",
"ember-rfc176-data": "^0.3.18",
"eslint-utils": "^3.0.0",
"estraverse": "^5.3.0",
"lodash.camelcase": "^4.3.0",
"lodash.kebabcase": "^4.1.1",
"requireindex": "^1.2.0",
"snake-case": "^3.0.3"
"snake-case": "^3.0.4"
},
"devDependencies": {
"@babel/core": "^7.25.9",
"@babel/eslint-parser": "^7.22.15",
"@babel/core": "^7.29.0",
"@babel/eslint-parser": "^7.28.6",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-decorators": "^7.23.2",
"@eslint/compat": "^2.0.1",
"@eslint/eslintrc": "^3.0.1",
"@eslint/js": "^9.19.0",
"@types/eslint": "^8.44.6",
"@typescript-eslint/parser": "^8.11.0",
"@vitest/coverage-v8": "^2.1.3",
"eslint": "^8.55.0",
"@babel/plugin-proposal-decorators": "^7.29.0",
"@eslint/compat": "^2.0.2",
"@eslint/eslintrc": "^3.3.3",
"@eslint/js": "^9.39.2",
"@types/eslint": "^8.56.12",
"@typescript-eslint/parser": "^8.56.0",
"@vitest/coverage-v8": "^2.1.9",
"eslint": "^8.57.1",
"eslint-config-prettier": "^10.1.8",
"eslint-doc-generator": "^2.1.2",
"eslint-doc-generator": "^2.4.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-eslint-plugin": "^5.1.1",
"eslint-plugin-eslint-plugin": "^5.5.1",
"eslint-plugin-filenames": "^1.3.2",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-import": "^2.32.0",
"eslint-plugin-markdown": "^5.1.0",
"eslint-plugin-n": "^17.11.1",
"eslint-plugin-unicorn": "^51.0.0",
"eslint-plugin-n": "^17.24.0",
"eslint-plugin-unicorn": "^51.0.1",
"eslint-remote-tester": "^3.0.1",
"globals": "^16.4.0",
"globals": "^16.5.0",
"jquery": "^3.7.1",
"jsdom": "^24.0.0",
"jsdom": "^24.1.3",
"markdownlint-cli": "^0.42.0",
"npm-package-json-lint": "^7.0.0",
"npm-package-json-lint": "^7.1.0",
"npm-run-all": "^4.1.5",
"prettier": "^3.0.3",
"release-plan": "^0.17.0",
"sort-package-json": "^2.6.0",
"typescript": "^5.2.2",
"typescript-eslint": "^8.7.0",
"vite": "^7.1.12",
"vitest": "^2.1.3"
"prettier": "^3.8.1",
"release-plan": "^0.17.4",
"sort-package-json": "^2.15.1",
"typescript": "^5.9.3",
"typescript-eslint": "^8.56.0",
"vite": "^7.3.1",
"vitest": "^2.1.9"
},
"peerDependencies": {
"@typescript-eslint/parser": "*",
Expand Down
Loading
Loading