Skip to content

Commit

Permalink
[eslint] tighten up rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Apr 13, 2023
1 parent 9799567 commit 8c155ba
Show file tree
Hide file tree
Showing 106 changed files with 1,405 additions and 1,370 deletions.
95 changes: 91 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,66 @@
"env": {
"node": true,
"es6": true,
"es2017": true,
},
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2020,
},
"rules": {
"arrow-body-style": [2, "as-needed"],
"arrow-parens": [2, "always"],
"arrow-spacing": [2, { "before": true, "after": true }],
"block-spacing": [2, "always"],
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
"comma-dangle": ["error", {
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "always-multiline",
}],
"comma-spacing": [2, { "before": false, "after": true }],
"comma-style": [2, "last"],
"curly": [2, "multi-line"],
"computed-property-spacing": [2, "never"],
"curly": [2, "all"],
"default-case": [2, { "commentPattern": "(?:)" }],
"default-case-last": [2],
"default-param-last": [2],
"dot-location": [2, "property"],
"dot-notation": [2, { "allowKeywords": true, "allowPattern": "throws" }],
"eol-last": [2, "always"],
"eqeqeq": [2, "allow-null"],
"func-call-spacing": 2,
"indent": [2, 2],
"for-direction": [2],
"function-call-argument-newline": [2, "consistent"],
"func-call-spacing": [2, "never"],
"implicit-arrow-linebreak": [2, "beside"],
"indent": [2, 2, {
"SwitchCase": 1,
"VariableDeclarator": 1,
"outerIIFEBody": 1,
"FunctionDeclaration": {
"parameters": 1,
"body": 1
},
"FunctionExpression": {
"parameters": 1,
"body": 1
},
"CallExpression": {
"arguments": 1
},
"ArrayExpression": 1,
"ObjectExpression": 1,
"ImportDeclaration": 1,
"flatTernaryExpressions": false,
}],
"jsx-quotes": [2, "prefer-double"],
"key-spacing": [2, {
"beforeColon": false,
"afterColon": true,
"mode": "strict",
}],
"keyword-spacing": ["error", {
"before": true,
"after": true,
Expand All @@ -40,27 +81,68 @@
"case": { "after": true }
}
}],
"linebreak-style": [2, "unix"],
"lines-around-directive": [2, {
"before": "always",
"after": "always",
}],
"max-len": 0,
"new-parens": 2,
"no-array-constructor": 2,
"no-compare-neg-zero": 2,
"no-cond-assign": [2, "always"],
"no-extra-parens": 2,
"no-multiple-empty-lines": [2, { "max": 1, "maxEOF": 1, "maxBOF": 0 }],
"no-return-assign": [2, "always"],
"no-trailing-spaces": 2,
"no-var": 2,
"object-curly-spacing": [2, "always"],
"object-shorthand": ["error", "always", {
"ignoreConstructors": false,
"avoidQuotes": true,
"avoidQuotes": false,
"avoidExplicitReturnArrows": true,
}],
"one-var": [2, "never"],
"operator-linebreak": [2, "none", {
"overrides": {
"?": "before",
":": "before",
"&&": "before",
"||": "before",
},
}],
"prefer-const": 2,
"prefer-object-spread": 2,
"prefer-rest-params": 2,
"prefer-template": 2,
"quote-props": [2, "as-needed", { "keywords": false }],
"quotes": [2, "single", {
"allowTemplateLiterals": true,
"avoidEscape": true,
}],
"rest-spread-spacing": [2, "never"],
"semi": [2, "always"],
"semi-spacing": [2, { "before": false, "after": true }],
"semi-style": [2, "last"],
"space-before-blocks": [2, { "functions": "always", "keywords": "always", "classes": "always" }],
"space-before-function-paren": ["error", {
"anonymous": "always",
"named": "never",
"asyncArrow": "always",
}],
"space-in-parens": [2, "never"],
"space-infix-ops": [2],
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"switch-colon-spacing": [2, { "after": true, "before": false }],
"template-curly-spacing": [2, "never"],
"template-tag-spacing": [2, "never"],
"unicode-bom": [2, "never"],
"use-isnan": [2, { "enforceForSwitchCase": true }],
"valid-typeof": [2],
"wrap-iife": [2, "outside", { "functionPrototypeMethods": true }],
"wrap-regex": [2],
"yield-star-spacing": [2, { "before": false, "after": true }],
"yoda": [2, "never", { "exceptRange": true, "onlyEquality": false }],

"eslint-plugin/consistent-output": [
"error",
Expand Down Expand Up @@ -116,6 +198,9 @@
"files": "resolvers/webpack/**",
"rules": {
"no-console": 1,
"prefer-template": 0,
"prefer-object-spread": 0,
"prefer-rest-params": 0,
},
"env": {
"es6": true,
Expand Down Expand Up @@ -143,6 +228,8 @@
"exports": "always-multiline",
"functions": "never"
}],
"prefer-object-spread": "off",
"prefer-template": "off",
"no-console": 1,
},
},
Expand Down
4 changes: 2 additions & 2 deletions config/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ module.exports = {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
'import/resolver': {
'node': {
'extensions': allExtensions,
node: {
extensions: allExtensions,
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions memo-parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const parserOptions = {
};

exports.parse = function parse(content, options) {
options = Object.assign({}, options, parserOptions);
options = { ...options, ...parserOptions };

if (!options.filePath) {
throw new Error('no file path provided!');
Expand All @@ -30,7 +30,7 @@ exports.parse = function parse(content, options) {
const key = keyHash.digest('hex');

let ast = cache.get(key);
if (ast != null) return ast;
if (ast != null) { return ast; }

const realParser = moduleRequire(options.parser);

Expand Down
9 changes: 3 additions & 6 deletions resolvers/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,14 @@ exports.resolve = function (source, file, config) {
};

function opts(file, config, packageFilter) {
return Object.assign({
// more closely matches Node (#333)
return { // more closely matches Node (#333)
// plus 'mjs' for native modules! (#939)
extensions: ['.mjs', '.js', '.json', '.node'],
},
config,
{
...config,

This comment has been minimized.

Copy link
@SimenB

SimenB Aug 7, 2023

Contributor

@ljharb this was released as a patch, breaking compatibility with Node 6. was that on purpose?

This comment has been minimized.

Copy link
@ljharb

ljharb Aug 7, 2023

Author Member

No, that was unintentional. I’ll release a new patch within the next 12 hours that addresses it.

This comment has been minimized.

Copy link
@ljharb

ljharb Aug 8, 2023

Author Member

Fixed the reason the tests weren't failing in 69fce5c; fixed the breakage in 10913e7. I'll release both resolvers shortly. Thanks!

This comment has been minimized.

Copy link
@ljharb

ljharb Aug 8, 2023

Author Member

Both resolvers have been released.

This comment has been minimized.

Copy link
@SimenB

SimenB Aug 8, 2023

Contributor

Thanks!

// path.resolve will handle paths relative to CWD
basedir: path.dirname(path.resolve(file)),
packageFilter,
});
};
}

function identity(x) { return x; }
Expand Down
1 change: 0 additions & 1 deletion resolvers/node/test/packageMains.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const resolver = require('../');

const file = path.join(__dirname, 'package-mains', 'dummy.js');


describe('packageMains', function () {
it('captures module', function () {
expect(resolver.resolve('./module', file)).property('path')
Expand Down
2 changes: 0 additions & 2 deletions resolvers/node/test/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ describe('paths', function () {
});
});


describe('core', function () {
it('returns found, but null path, for core Node modules', function () {
const resolved = node.resolve('fs', './test/file.js');
Expand All @@ -20,7 +19,6 @@ describe('core', function () {
});
});


describe('default options', function () {

it('finds .json files', function () {
Expand Down
20 changes: 9 additions & 11 deletions resolvers/webpack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ exports.resolve = function (source, file, settings) {
if (!configPath || !path.isAbsolute(configPath)) {
// if not, find ancestral package.json and use its directory as base for the path
packageDir = findRoot(path.resolve(file));
if (!packageDir) throw new Error('package not found above ' + file);
if (!packageDir) { throw new Error('package not found above ' + file); }
}

configPath = findConfigPath(configPath, packageDir);
Expand Down Expand Up @@ -108,7 +108,7 @@ exports.resolve = function (source, file, settings) {
}

if (Array.isArray(webpackConfig)) {
webpackConfig = webpackConfig.map(cfg => {
webpackConfig = webpackConfig.map((cfg) => {
if (typeof cfg === 'function') {
return cfg(env, argv);
}
Expand Down Expand Up @@ -284,16 +284,15 @@ function createWebpack1ResolveSync(webpackRequire, resolveConfig, plugins) {
new ResultSymlinkPlugin(),
);


const resolvePlugins = [];

// support webpack.ResolverPlugin
if (plugins) {
plugins.forEach(function (plugin) {
if (
plugin.constructor &&
plugin.constructor.name === 'ResolverPlugin' &&
Array.isArray(plugin.plugins)
plugin.constructor
&& plugin.constructor.name === 'ResolverPlugin'
&& Array.isArray(plugin.plugins)
) {
resolvePlugins.push.apply(resolvePlugins, plugin.plugins);
}
Expand Down Expand Up @@ -324,10 +323,10 @@ function makeRootPlugin(ModulesInRootPlugin, name, root) {
/* eslint-enable */

function findExternal(source, externals, context, resolveSync) {
if (!externals) return false;
if (!externals) { return false; }

// string match
if (typeof externals === 'string') return (source === externals);
if (typeof externals === 'string') { return source === externals; }

// array: recurse
if (Array.isArray(externals)) {
Expand Down Expand Up @@ -384,8 +383,8 @@ function findExternal(source, externals, context, resolveSync) {

// else, vanilla object
for (const key in externals) {
if (!has(externals, key)) continue;
if (source === key) return true;
if (!has(externals, key)) { continue; }
if (source === key) { return true; }
}
return false;
}
Expand All @@ -396,7 +395,6 @@ function findConfigPath(configPath, packageDir) {
});
let extension;


if (configPath) {
// extensions is not reused below, so safe to mutate it here.
extensions.reverse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'path';
export default {
resolve: {
alias: {
'foo': path.join(__dirname, 'some', 'goofy', 'path', 'foo.js'),
foo: path.join(__dirname, 'some', 'goofy', 'path', 'foo.js'),
},
modules: [
path.join(__dirname, 'src'),
Expand All @@ -17,7 +17,7 @@ export default {
},

externals: [
{ 'jquery': 'jQuery' },
{ jquery: 'jQuery' },
'bootstrap',
],
};
1 change: 0 additions & 1 deletion resolvers/webpack/test/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const path = require('path');

const resolve = require('../index').resolve;


const file = path.join(__dirname, 'files', 'dummy.js');
const extensions = path.join(__dirname, 'custom-extensions', 'dummy.js');

Expand Down
1 change: 0 additions & 1 deletion resolvers/webpack/test/fallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const path = require('path');

const resolve = require('../index').resolve;


const file = path.join(__dirname, 'files', 'src', 'dummy.js');

describe('fallback', function () {
Expand Down
1 change: 0 additions & 1 deletion resolvers/webpack/test/loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const path = require('path');

const resolve = require('../index').resolve;


const file = path.join(__dirname, 'files', 'dummy.js');

describe('inline loader syntax', function () {
Expand Down
1 change: 0 additions & 1 deletion resolvers/webpack/test/packageMains.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const resolver = require('../');

const file = path.join(__dirname, 'package-mains', 'dummy.js');


describe('packageMains', function () {

it('captures module', function () {
Expand Down
1 change: 0 additions & 1 deletion resolvers/webpack/test/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const path = require('path');

const resolve = require('../index').resolve;


const file = path.join(__dirname, 'files', 'src', 'dummy.js');
const webpackDir = path.join(__dirname, 'different-package-location');

Expand Down
4 changes: 2 additions & 2 deletions scripts/testAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const spawnOptions = {
spawnSync(
npmPath,
['test'],
Object.assign({ cwd: __dirname }, spawnOptions));
{ cwd: __dirname, ...spawnOptions });

for (const resolverDir of resolverDirectories) {
spawnSync(
npmPath,
['test'],
Object.assign({ cwd: resolverDir }, spawnOptions));
{ cwd: resolverDir, ...spawnOptions });
}
Loading

0 comments on commit 8c155ba

Please sign in to comment.