Skip to content

Commit

Permalink
Create browser config
Browse files Browse the repository at this point in the history
For modern browsers.

Signed-off-by: Kevin Locke <[email protected]>
  • Loading branch information
kevinoid committed Dec 3, 2024
1 parent 7613d69 commit 81ed561
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ This package includes configurations for several different environments:

| Name | Description |
| --------------------------------------- | ---------------------------------------- |
| `@kevinoid/eslint-config/browser` | Modern browsers |
| `@kevinoid/eslint-config/ie11` | Browsers including Internet Explorer 11. |
| `@kevinoid/eslint-config/nodejs` | Node 6 and later. |
| `@kevinoid/eslint-config/webextensions` | [Browser Extensions](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions) |
Expand Down
50 changes: 50 additions & 0 deletions browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// ESLint configuration for JS run directly in (modern) browsers.
// <https://eslint.org/docs/user-guide/configuring>

"use strict";

module.exports = {
// Based on Airbnb with changes to match Node core and my prefs.
"extends": [
"airbnb-base",

// ESLint built-in rules
"./rules/es6",
"./rules/best-practices",
"./rules/possible-errors",
"./rules/style",
"./rules/variables",

// Plugin rules
"./rules/jsdoc",
"./rules/promise",
"./rules/regexp",
"./rules/unicorn"
],

"parserOptions": {
"sourceType": "script",
// airbnb-base disables generators due to regenerator-runtime overhead.
// Modern browsers support generators without regenerator, so allow.
"ecmaFeatures": {
"generators": true
}
},

"env": {
"browser": true,
// Disable node env added by airbnb-base/legacy
"node": false
},

"rules": {
// allow console (which is always supported and conventional for logging)
"no-console": "off",

// require 'use strict' in global scope
"strict": ["error", "global"],

// don't prefer modules
"unicorn/prefer-module": "off"
}
};
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"!**/.*"
],
"exports": {
"./browser": "./browser.js",
"./browser.js": "./browser.js",
"./ie11": "./ie11.js",
"./ie11.js": "./ie11.js",
"./package.json": "./package.json",
Expand All @@ -43,8 +45,9 @@
"postpublish": "git push --follow-tags origin main && echo Remember to update GitHub Releases from CHANGELOG.md",
"preversion": "depcheck --ignores=\"eslint-*,rimraf\" && david && git-branch-is main && hub-ci-status -vv --wait",
"test": "npm run test-peer-versions-ci && npm run lint && npm run test-eslint",
"test-eslint": "npm run test-eslint-ie11 && npm run test-eslint-node && npm run test-eslint-webextensions && npm run test-eslint-wsh",
"test-eslint": "npm run test-eslint-browser && npm run test-eslint-ie11 && npm run test-eslint-node && npm run test-eslint-webextensions && npm run test-eslint-wsh",
"//": "Test that config can be loaded and works on empty input. Note: echo prints 'ECHO is on.' in cmd.exe, : produces no output in cmd.exe or sh.",
"test-eslint-browser": ": | eslint --no-eslintrc -c browser.js --stdin",
"test-eslint-ie11": ": | eslint --no-eslintrc -c ie11.js --stdin",
"test-eslint-node": ": | eslint --no-eslintrc -c nodejs.js --stdin",
"test-eslint-webextensions": ": | eslint --no-eslintrc -c webextensions.js --stdin",
Expand Down

0 comments on commit 81ed561

Please sign in to comment.