Skip to content

Commit

Permalink
Fix many tests, add hot-patching to get the ball rolling
Browse files Browse the repository at this point in the history
  • Loading branch information
onigoetz committed Aug 31, 2021
1 parent 950fa8d commit f348d9a
Show file tree
Hide file tree
Showing 14 changed files with 291 additions and 118 deletions.
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -19,12 +19,14 @@
"test": "jest --projects packages/integration packages/eslint-plugin-swissquote packages/stylelint-config-swissquote packages/crafty-runner-webpack packages/crafty && cd packages/rollup-plugin-eslint && yarn test",
"test:ci": "sh test_ci.sh",
"publish:canary": "oao publish --no-git-commit --no-check-uncommitted --no-changelog --publish-tag canary --bump-dependent-reqs=exact",
"publish:all": "oao publish --no-changelog --bump-dependent-reqs=exact"
"publish:all": "oao publish --no-changelog --bump-dependent-reqs=exact",
"postinstall": "patch-package"
},
"dependencies": {
"jest": "27.1.0",
"markdown-spellcheck": "1.3.1",
"oao": "2.0.2",
"patch-package": "^6.4.7",
"write-good": "1.0.8"
},
"engines": {
Expand Down
7 changes: 6 additions & 1 deletion packages/crafty-preset-babel/src/gulp.js
Expand Up @@ -19,7 +19,12 @@ module.exports = function createTask(crafty, bundle, StreamHandler) {
toTempFile
} = require("@swissquote/crafty-preset-eslint/src/eslintConfigurator");
const eslint = require("gulp-eslint7");
stream.add(eslint(toTempFile(crafty.config.eslint))).add(eslint.format());
stream.add(eslint(
{
resolver: require.resolve("@swissquote/crafty-preset-eslint/src/resolver.js"),
overrideConfigFile: toTempFile(crafty.config.eslint)
}
)).add(eslint.format());

// Fail the build if we have linting
// errors and we build directly
Expand Down
2 changes: 1 addition & 1 deletion packages/crafty-preset-eslint/src/commands/jsLint.js
Expand Up @@ -20,4 +20,4 @@ process.argv.push(require.resolve("../resolver.js"))
process.argv.push("--config");
process.argv.push(tmpfile);

require("eslint/bin/eslint");
require(".bin/eslint");
1 change: 1 addition & 0 deletions packages/crafty-preset-eslint/src/index.js
Expand Up @@ -80,6 +80,7 @@ module.exports = {
weight: -20,
options: {
overrideConfigFile: toTempFile(crafty.config.eslint),
resolver: require.resolve("@swissquote/crafty-preset-eslint/src/resolver.js"),
throwOnError: crafty.getEnvironment() === "production",
exclude: [/node_modules/],
include: crafty.config.eslintExtensions.map(
Expand Down
2 changes: 1 addition & 1 deletion packages/crafty-preset-eslint/src/resolver.js
Expand Up @@ -3,7 +3,7 @@ const {
} = require("@eslint/eslintrc");

function resolve(moduleName, relativeToPath) {
console.log("resolving", { moduleName, relativeToPath });
//console.log({moduleName, relativeToPath});
try {
// First check for the module relative to the current location
return ModuleResolver.resolve(moduleName, __filename);
Expand Down
7 changes: 6 additions & 1 deletion packages/crafty-preset-swc/src/gulp.js
Expand Up @@ -19,7 +19,12 @@ module.exports = function createTask(crafty, bundle, StreamHandler) {
toTempFile
} = require("@swissquote/crafty-preset-eslint/src/eslintConfigurator");
const eslint = require("gulp-eslint7");
stream.add(eslint(toTempFile(crafty.config.eslint))).add(eslint.format());
stream.add(eslint(
{
resolver: require.resolve("@swissquote/crafty-preset-eslint/src/resolver.js"),
overrideConfigFile: toTempFile(crafty.config.eslint)
}
)).add(eslint.format());

// Fail the build if we have linting
// errors and we build directly
Expand Down
7 changes: 6 additions & 1 deletion packages/crafty-preset-typescript/src/gulp.js
Expand Up @@ -20,7 +20,12 @@ module.exports = function createTask(crafty, bundle, StreamHandler) {
} = require("@swissquote/crafty-preset-eslint/src/eslintConfigurator");
const eslint = require("gulp-eslint7");
stream
.add(eslint({ configFile: toTempFile(crafty.config.eslint) }))
.add(eslint(
{
resolver: require.resolve("@swissquote/crafty-preset-eslint/src/resolver.js"),
overrideConfigFile: toTempFile(crafty.config.eslint)
}
))
.add(eslint.format());

// Fail the build if we have linting
Expand Down
Expand Up @@ -17,9 +17,6 @@ exports[`Generates IDE Helper 2`] = `
// This file is generated to improve IDE Integration
// You don't need to commit this file, nor need it to run \`crafty build\`
// Fix module resolution
require(\\"__PATH__/packages/crafty-preset-eslint/src/patchModuleResolver.js\\");
module.exports = {
\\"plugins\\": [
\\"@swissquote/swissquote\\"
Expand Down
Expand Up @@ -17,9 +17,6 @@ exports[`Generates IDE Helper 2`] = `
// This file is generated to improve IDE Integration
// You don't need to commit this file, nor need it to run \`crafty build\`
// Fix module resolution
require(\\"__PATH__/packages/crafty-preset-eslint/src/patchModuleResolver.js\\");
module.exports = {
\\"plugins\\": [
\\"@swissquote/swissquote\\"
Expand Down
36 changes: 36 additions & 0 deletions patches/@eslint+eslintrc+1.0.0.patch
@@ -0,0 +1,36 @@
diff --git a/node_modules/@eslint/eslintrc/dist/eslintrc.cjs b/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
index b8d5f8c..bbd1ccc 100644
--- a/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
+++ b/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
@@ -3228,11 +3228,11 @@ class ConfigArrayFactory {
_loadParser(nameOrPath, ctx) {
debug$2("Loading parser %j from %s", nameOrPath, ctx.filePath);

- const { cwd } = internalSlotsMap$1.get(this);
+ const { cwd, resolver } = internalSlotsMap$1.get(this);
const relativeTo = ctx.filePath || path__default['default'].join(cwd, "__placeholder__.js");

try {
- const filePath = resolve(nameOrPath, relativeTo);
+ const filePath = resolver.resolve(nameOrPath, relativeTo);

writeDebugLogForLoading(nameOrPath, relativeTo, filePath);

@@ -3279,7 +3279,7 @@ class ConfigArrayFactory {
_loadPlugin(name, ctx) {
debug$2("Loading plugin %j from %s", name, ctx.filePath);

- const { additionalPluginPool } = internalSlotsMap$1.get(this);
+ const { additionalPluginPool, resolver } = internalSlotsMap$1.get(this);
const request = normalizePackageName(name, "eslint-plugin");
const id = getShorthandName(request, "eslint-plugin");
const relativeTo = path__default['default'].join(ctx.pluginBasePath, "__placeholder__.js");
@@ -3320,7 +3320,7 @@ class ConfigArrayFactory {
let error;

try {
- filePath = resolve(request, relativeTo);
+ filePath = resolver.resolve(request, relativeTo);
} catch (resolveError) {
error = resolveError;
/* istanbul ignore else */
68 changes: 68 additions & 0 deletions patches/eslint+8.0.0-beta.1.patch
@@ -0,0 +1,68 @@
diff --git a/node_modules/eslint/lib/cli-engine/cli-engine.js b/node_modules/eslint/lib/cli-engine/cli-engine.js
index aae7160..45c7156 100644
--- a/node_modules/eslint/lib/cli-engine/cli-engine.js
+++ b/node_modules/eslint/lib/cli-engine/cli-engine.js
@@ -595,6 +595,7 @@ class CLIEngine {
cwd: options.cwd,
ignorePath: options.ignorePath,
resolvePluginsRelativeTo: options.resolvePluginsRelativeTo,
+ resolver: options.resolver,
rulePaths: options.rulePaths,
specificConfigPath: options.configFile,
useEslintrc: options.useEslintrc,
diff --git a/node_modules/eslint/lib/cli.js b/node_modules/eslint/lib/cli.js
index 477310d..af6a75a 100644
--- a/node_modules/eslint/lib/cli.js
+++ b/node_modules/eslint/lib/cli.js
@@ -83,6 +83,7 @@ function translateOptions({
quiet,
reportUnusedDisableDirectives,
resolvePluginsRelativeTo,
+ resolver,
rule,
rulesdir
}) {
@@ -119,6 +120,7 @@ function translateOptions({
overrideConfigFile: config,
reportUnusedDisableDirectives: reportUnusedDisableDirectives ? "error" : void 0,
resolvePluginsRelativeTo,
+ resolver,
rulePaths: rulesdir,
useEslintrc: eslintrc
};
diff --git a/node_modules/eslint/lib/eslint/eslint.js b/node_modules/eslint/lib/eslint/eslint.js
index b4a1d02..89213d0 100644
--- a/node_modules/eslint/lib/eslint/eslint.js
+++ b/node_modules/eslint/lib/eslint/eslint.js
@@ -173,6 +173,7 @@ function processOptions({
plugins = {},
reportUnusedDisableDirectives = null, // ← should be null by default because if it's a string then it overrides the 'reportUnusedDisableDirectives' setting in config files. And we cannot use `overrideConfig.reportUnusedDisableDirectives` instead because we cannot configure the `error` severity with that.
resolvePluginsRelativeTo = null, // ← should be null by default because if it's a string then it suppresses RFC47 feature.
+ resolver = null,
rulePaths = [],
useEslintrc = true,
...unknownOptions
@@ -305,6 +306,7 @@ function processOptions({
ignorePath,
reportUnusedDisableDirectives,
resolvePluginsRelativeTo,
+ resolver: resolver ? require(resolver) : undefined,
rulePaths,
useEslintrc
};
diff --git a/node_modules/eslint/lib/options.js b/node_modules/eslint/lib/options.js
index 2dd186d..dfe32c1 100644
--- a/node_modules/eslint/lib/options.js
+++ b/node_modules/eslint/lib/options.js
@@ -115,6 +115,11 @@ module.exports = optionator({
type: "path::String",
description: "A folder where plugins should be resolved from, CWD by default"
},
+ {
+ option: "resolver",
+ type: "path::String",
+ description: "Absolute path to a resolver module"
+ },
{
heading: "Specifying rules and plugins"
},
13 changes: 13 additions & 0 deletions patches/eslint-plugin-import+2.24.2.patch
@@ -0,0 +1,13 @@
diff --git a/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js b/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js
index bda956c..29be68e 100644
--- a/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js
+++ b/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js
@@ -17,7 +17,7 @@ var _arrayIncludes = require('array-includes');var _arrayIncludes2 = _interopReq
* @author René Fermann
*/ // eslint/lib/util/glob-util has been moved to eslint/lib/util/glob-utils with version 5.3
// and has been moved to eslint/lib/cli-engine/file-enumerator in version 6
-var listFilesToProcess = void 0;try {var FileEnumerator = require('eslint/lib/cli-engine/file-enumerator').FileEnumerator;
+var listFilesToProcess = void 0;try {var FileEnumerator = require('eslint/use-at-your-own-risk').FileEnumerator;
listFilesToProcess = function listFilesToProcess(src, extensions) {
var e = new FileEnumerator({
extensions: extensions });
70 changes: 70 additions & 0 deletions patches/gulp-eslint7+0.3.1.patch
@@ -0,0 +1,70 @@
diff --git a/node_modules/gulp-eslint7/index.js b/node_modules/gulp-eslint7/index.js
index 533550e..7592722 100644
--- a/node_modules/gulp-eslint7/index.js
+++ b/node_modules/gulp-eslint7/index.js
@@ -70,6 +70,11 @@ function gulpEslint(options) {
const { eslintOptions, quiet, warnIgnored } = migrateOptions(options);
const linter = new ESLint(eslintOptions);

+ // yes that's ugly, we'll see for a better solution in a PR
+ resolveFormatter(linter, "stylish").then(formatter => {
+ gulpEslint.formatter = formatter;
+ })
+
return transform((file, enc, cb) => {
lintFile(linter, file, quiet, warnIgnored)
.then(() => cb(null, file))
@@ -174,10 +179,9 @@ gulpEslint.failAfterError = () => {
* @returns {stream} gulp file stream
*/
gulpEslint.formatEach = (formatter, writable) => {
- formatter = resolveFormatter(formatter);
writable = resolveWritable(writable);

- return gulpEslint.result(result => writeResults([result], formatter, writable));
+ return gulpEslint.result(result => writeResults([result], gulpEslint.formatter, writable));
};

/**
@@ -188,13 +192,12 @@ gulpEslint.formatEach = (formatter, writable) => {
* @returns {stream} gulp file stream
*/
gulpEslint.format = (formatter, writable) => {
- formatter = resolveFormatter(formatter);
writable = resolveWritable(writable);

return gulpEslint.results(results => {
// Only format results if files has been lint'd
if (results.length) {
- writeResults(results, formatter, writable);
+ writeResults(results, gulpEslint.formatter, writable);
}
});
};
diff --git a/node_modules/gulp-eslint7/util.js b/node_modules/gulp-eslint7/util.js
index bf44540..9635b59 100644
--- a/node_modules/gulp-eslint7/util.js
+++ b/node_modules/gulp-eslint7/util.js
@@ -282,11 +282,11 @@ exports.filterResult = (result, filter) => {
* @param {(String|Function)} [formatter=stylish] - A name to resolve as a formatter. If a function is provided, the same function is returned.
* @returns {Function} An ESLint formatter
*/
-exports.resolveFormatter = (formatter) => {
+exports.resolveFormatter = async (linter, formatter) => {
// use ESLint to look up formatter references
if (typeof formatter !== 'function') {
// load formatter (module, relative to cwd, ESLint formatter)
- formatter = CLIEngine.getFormatter(formatter);
+ formatter = linter.loadFormatter(formatter);
}

return formatter;
@@ -321,7 +321,7 @@ exports.writeResults = (results, formatter, writable) => {

const firstResult = results.find(result => result.config);

- const message = formatter(results, firstResult ? firstResult.config : {});
+ const message = formatter.format(results, firstResult ? firstResult.config : {});
if (writable && message != null && message !== '') {
writable(message);
}

0 comments on commit f348d9a

Please sign in to comment.