Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable more undesired syntax #207

Merged
merged 5 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@eslint/eslintrc": "^0.4.0",
"@lavamoat/allow-scripts": "^2.0.3",
"@metamask/auto-changelog": "^2.3.0",
"@metamask/utils": "^2.1.0",
"eslint": "^7.23.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-import": "^2.22.1",
Expand Down
20 changes: 19 additions & 1 deletion packages/base/rules-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,25 @@
"no-regex-spaces": "error",
"no-reserved-keys": "off",
"no-restricted-globals": ["error", "event"],
"no-restricted-syntax": ["error", "SequenceExpression"],
"no-restricted-syntax": [
"error",
{
"selector": "FunctionExpression",
"message": "Function expressions are not allowed"
},
{
"selector": "WithStatement",
"message": "With statements are not allowed"
},
{
"selector": "BinaryExpression[operator='in']",
"message": "The \"in\" operator is not allowed"
},
{
"selector": "SequenceExpression",
"message": "Sequence expressions are not allowed"
}
],
"no-return-assign": ["error", "except-parens"],
"no-script-url": "error",
"no-self-assign": "error",
Expand Down
24 changes: 21 additions & 3 deletions packages/base/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ module.exports = {
curly: ['error', 'all'],
'no-tabs': 'error',

// Not required by prettier, but potentially gotchas.
'no-restricted-syntax': ['error', 'SequenceExpression'],

/* Core rules */
'accessor-pairs': 'error',
'array-callback-return': 'error',
Expand Down Expand Up @@ -136,6 +133,27 @@ module.exports = {
],
'no-proto': 'error',
'no-restricted-globals': ['error', 'event'],
'no-restricted-syntax': [
'error',
{
selector: 'FunctionExpression',
message: 'Function expressions are not allowed',
},
{
selector: 'WithStatement',
message: 'With statements are not allowed',
},
{
selector: `BinaryExpression[operator='in']`,
message: 'The "in" operator is not allowed',
},
// Sequence expressions have potential gotchas with Prettier, and are also
// weird!
{
selector: 'SequenceExpression',
message: 'Sequence expressions are not allowed',
},
],
'no-return-assign': ['error', 'except-parens'],
'no-script-url': 'error',
'no-self-compare': 'error',
Expand Down
7 changes: 4 additions & 3 deletions scripts/validate-configs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { readdirSync, readFileSync, promises: fs } = require('fs');
const pathUtils = require('path');
const { FlatCompat } = require('@eslint/eslintrc');
const { hasProperty } = require('@metamask/utils');
const eslintRecommendedConfig = require('eslint/conf/eslint-recommended');
const {
configs: { recommended: prettierConfig },
Expand Down Expand Up @@ -138,7 +139,7 @@ function validatePrettierRules(
violations,
) {
prettierRules.forEach((ruleName) => {
if (ruleName in flatRules && flatRules[ruleName] !== OFF) {
if (hasProperty(flatRules, ruleName) && flatRules[ruleName] !== OFF) {
violations[packageName].push(ruleName);
}
});
Expand Down Expand Up @@ -166,7 +167,7 @@ function validateConfigMinimalism(
Object.entries(config.rules || {}).forEach(([ruleName, ruleValue]) => {
if (
deepEqual(flatExtendedRules[ruleName], ruleValue) ||
(!(ruleName in flatExtendedRules) && ruleValue === OFF)
(!hasProperty(flatExtendedRules, ruleName) && ruleValue === OFF)
) {
violations[packageName].push(ruleName);
}
Expand Down Expand Up @@ -393,7 +394,7 @@ function getRequiredPrettierRules() {
function getFlatRules(flatConfig, normalizeRules = true) {
// Flatten the config array into a single object
const rawFlatRules = flatConfig.reduce((flatRules, config) => {
if (RULES in config) {
if (hasProperty(config, RULES)) {
return {
...flatRules,
...config[RULES],
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@
semver "^7.3.5"
yargs "^17.0.1"

"@metamask/utils@^2.1.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@metamask/utils/-/utils-2.1.0.tgz#a65eaa0932b863383844ec323e05e293d8e718ab"
integrity sha512-4PHdo5B1ifpw6GbsdlDpp8oqA++rddSmt2pWBHtIGGL2tQMvmfHdaDDSns4JP9iC+AbMogVcUpv5Vt8ow1zsRA==
dependencies:
fast-deep-equal "^3.1.3"

"@nodelib/fs.scandir@2.1.3":
version "2.1.3"
resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.3.tgz#3a582bdb53804c6ba6d146579c46e52130cf4a3b"
Expand Down