nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: javierbrea/eslint-plugin-boundaries
Pull request #305 (2023-08-19 07:31:04)

Fix null error when using capture matchers in element without captured values
- fix: Do not throw error when rule contains matchers for captured values but element has not captured values


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ad2c4bb..674a3cf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
 
 ### Fixed
 - fix(#295): Replace template values in custom messages using a Regexp, so it replaces all occurrences
+- fix: Do not throw error when rule contains matchers for captured values but element has not captured values
 
 ### Changed
 - chore(deps): Update dependencies
diff --git a/src/helpers/rules.js b/src/helpers/rules.js
index 82dc34a..089ef30 100644
--- a/src/helpers/rules.js
+++ b/src/helpers/rules.js
@@ -62,6 +62,9 @@ function micromatchPatternReplacingObjectsValues(pattern, object) {
 function isObjectMatch(objectWithMatchers, object, objectsWithValuesToReplace) {
   return Object.keys(objectWithMatchers).reduce((isMatch, key) => {
     if (isMatch) {
+      if (!object) {
+        return false;
+      }
       const micromatchPattern = micromatchPatternReplacingObjectsValues(
         objectWithMatchers[key],
         objectsWithValuesToReplace,


Test patch:
diff --git a/test/rules/one-level/element-types.spec.js b/test/rules/one-level/element-types.spec.js
index 3bae9ff..ab9b3ea 100644
--- a/test/rules/one-level/element-types.spec.js
+++ b/test/rules/one-level/element-types.spec.js
@@ -440,6 +440,10 @@ test(
           from: "components",
           disallow: ["modules"],
         },
+        {
+          from: [["components", { elementName: "component-a" }]],
+          allow: [["modules", { elementName: "module-b" }]],
+        },
       ],
     },
   ],
Repository: fgnass/node-dev
Pull request #134 (2016-05-18 12:10:19)

Proof against weird `require.extensions`
Hi, I’m using node-dev to run my tests and restart them whenever I change a file. In my tests I’m using [mock-fs](https://github.com/tschaub/mock-fs) which seems to hook into `require.extensions` itself – in quite a weird way.

As a result, starting `node-dev` failed with the following message:

```js
TypeError: Cannot read property 'name' of undefined
    at updateHooks (/…/node_modules/node-dev/lib/hook.js:37:13)
```

I looked into that – the cause was a weird `{ '.coffee': undefined }` property registered at `require.extensions`.

Here’s the fix – along with a test where I’ve reproduced the problem.


Patch:
diff --git a/lib/hook.js b/lib/hook.js
index 7687085..a921967 100644
--- a/lib/hook.js
+++ b/lib/hook.js
@@ -34,7 +34,7 @@ module.exports = function (cfg, wrapper, callback) {
   function updateHooks() {
     for (var ext in require.extensions) {
       var fn = require.extensions[ext];
-      if (fn.name !== 'nodeDevHook') {
+      if (typeof fn === 'function' && fn.name !== 'nodeDevHook') {
         require.extensions[ext] = createHook(fn);
       }
     }


Test patch:
diff --git a/test/fixture/modify-extensions.js b/test/fixture/modify-extensions.js
new file mode 100644
index 0000000..02aa42f
--- /dev/null
+++ b/test/fixture/modify-extensions.js
@@ -0,0 +1,1 @@
+require.extensions.bogus = undefined;
diff --git a/test/index.js b/test/index.js
index 07c0c15..b2872b5 100644
--- a/test/index.js
+++ b/test/index.js
@@ -259,3 +259,10 @@ test('should allow graceful shutdowns', function (t) {
     }
   });
 });
+
+test('should be resistant to breaking `require.extensions`', function (t) {
+  spawn('modify-extensions.js', function (out) {
+    t.notOk(/TypeError/.test(out));
+  });
+  setTimeout(t.end.bind(t), 500);
+});
Repository: fgnass/node-dev
Pull request #135 (2016-05-20 11:02:16)

Ensure method patching works when filename arguments are missing
Dust.js templating engine runs code via vm.runInContext without the third filename arguments, which causes property access on undefined value:

```javascript
TypeError: Cannot read property 'filename' of undefined
    at Object.obj.(anonymous function) [as runInContext] (.../node-dev/lib/hook.js:26:55)
```

To reproduce:

```javascript
var vm = require('vm');
vm.runInContext('log("hello world")', vm.createContext({log: console.log}));
```


Patch:
diff --git a/lib/hook.js b/lib/hook.js
index a921967..44868fd 100644
--- a/lib/hook.js
+++ b/lib/hook.js
@@ -22,7 +22,9 @@ module.exports = function (cfg, wrapper, callback) {
     if (!orig) return;
     obj[method] = function () {
       var opts = arguments[optionsArgIndex];
-      var file = typeof opts == 'string' ? opts : opts.filename;
+      var file = null;
+      if(opts)
+        file = typeof opts == 'string' ? opts : opts.filename;
       if (file) callback(file);
       return orig.apply(this, arguments);
     };


Test patch:
diff --git a/test/fixture/vmtest.js b/test/fixture/vmtest.js
index 20e8fb0..8d7ddfc 100644
--- a/test/fixture/vmtest.js
+++ b/test/fixture/vmtest.js
@@ -3,7 +3,11 @@ var fs = require('fs');
 var file = __dirname + '/log.js';
 var str = fs.readFileSync(file, 'utf8');
 
-vm.runInNewContext(str, { module: {}, require: require, console: console }, file);
+if(process.argv.length > 2 && process.argv[2] === 'nofile') {
+  vm.runInNewContext(str, { module: {}, require: require, console: console });
+} else {
+  vm.runInNewContext(str, { module: {}, require: require, console: console }, file);
+}
 
 // Listen for events to keep running
 process.on('message', function () {});
diff --git a/test/index.js b/test/index.js
index b2872b5..f9f0914 100644
--- a/test/index.js
+++ b/test/index.js
@@ -132,6 +132,10 @@ test('should support vm functions', function (t) {
   run('vmtest.js', t.end.bind(t));
 });
 
+test('should support vm functions with missing file argument', function (t) {
+  run('vmtest.js nofile', t.end.bind(t));
+});
+
 test('should support coffee-script', function (t) {
   run('server.coffee', t.end.bind(t));
 });