Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

grunt-time-bomb

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-time-bomb - npm Package Compare versions

Comparing version 0.1.3 to 0.1.7

.eslintrc.json

0

Gruntfile.js

@@ -0,0 +0,0 @@ /*

13

package.json
{
"name": "grunt-time-bomb",
"description": "Detect time bombs in source code comments.",
"version": "0.1.3",
"version": "0.1.7",
"homepage": "https://github.com/tobiashennig/grunt-time-bomb",

@@ -30,6 +30,7 @@ "author": {

"devDependencies": {
"grunt-contrib-jshint": "^0.9.2",
"grunt-contrib-clean": "^0.5.0",
"grunt-contrib-nodeunit": "^0.3.3",
"grunt": "~0.4.5"
"eslint-config-standard": "^5.3.5",
"eslint-plugin-standard": "^2.0.0",
"grunt-contrib-clean": "^1.0.0",
"grunt-contrib-nodeunit": "^1.0.0",
"grunt": "^1.0.1"
},

@@ -43,4 +44,4 @@ "peerDependencies": {

"dependencies": {
"acorn": "^2.7.0"
"acorn": "^3.2.0"
}
}

@@ -68,3 +68,7 @@ # grunt-time-bomb

## Release History
* [0.1.7] Show all exploded time bombs, fix #4
* [0.1.6] Fix #5
* [0.1.5] Fix #6
* [0.1.4] Update dev-/dependencies
* [0.1.3] Update peer dependency to support Grunt 1.0, fix #1, #2
* [0.1.0] Initial version

@@ -1,47 +0,75 @@

var acorn = require('acorn');
var Timers = require('./timers');
var acorn = require('acorn/dist/acorn_loose')
var Timers = require('./timers')
module.exports = function(grunt) {
function BombDetector(files) {
this.key = '@timer';
this.testRegExp = new RegExp(this.key + '[^\\w]', 'i');
this.dateRegExp = new RegExp(this.key + '[^\\w]+(\\d{4}-\\d{2}-\\d{2})', 'i');
this.timers = new Timers();
module.exports = function (grunt) {
function BombDetector (files) {
this.key = '@timer'
this.testRegExp = new RegExp(this.key + '[^\\w]', 'i')
this.timers = new Timers()
}
BombDetector.prototype.parse = function(files) {
var comments = [], options = {};
BombDetector.prototype.parse = function (files) {
var comments = []
var options = {}
files.filter(function(filepath) {
files.filter(function (filepath) {
// Remove nonexistent files (it's up to you to filter or warn here).
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return false;
grunt.log.warn('Source file "' + filepath + '" not found.')
return false
}
return true;
}).map(function(filepath) {
comments = options.onComment = [];
acorn.parse(grunt.file.read(filepath), options);
this.parseComments(filepath, comments);
}, this);
};
return true
}).map(function (filepath) {
comments = options.onComment = []
acorn.parse_dammit(grunt.file.read(filepath), options)
this.parseComments(filepath, comments)
}, this)
}
BombDetector.prototype.parseComments = function(filepath, comments) {
comments.forEach(function(comment) {
if (this.isTimer(comment)) {
this.timers.add(filepath, this.getDateFromTimer(comment));
BombDetector.prototype.parseComments = function (filepath, comments) {
var timer
comments.forEach(function (comment) {
if (this.isTimer(comment.value)) {
timer = this.parseTimer(filepath, comment.value)
this.timers.add(timer)
}
}, this);
};
}, this)
}
BombDetector.prototype.isTimer = function(comment) {
return this.testRegExp.test(comment.value);
};
BombDetector.prototype.isTimer = function (comment) {
return this.testRegExp.test(comment)
}
BombDetector.prototype.getDateFromTimer = function(timer) {
var result = this.dateRegExp.exec(timer.value);
return (result !== null) ? new Date(result[1]) : false;
};
BombDetector.prototype.parseTimer = function (file, comment) {
var parts = comment.match(/@timer[^\w]+(\d{4}-\d{2}-\d{2})[ \t]*(\d{2}:\d{2}(?::\d{2})*)*(?:[^\w])*(.*)$/im)
var timer = {
file: file,
date: this.parseDate(parts[1], parts[2]),
text: this.parseText(parts[3])
}
return timer
}
return BombDetector;
};
BombDetector.prototype.parseDate = function (date, time) {
var dateTime
if (!time || time === '') {
time = '00:00'
}
if (time.length === 5) {
time += ':00'
}
dateTime = date + 'T' + time + 'Z'
return new Date(dateTime)
}
BombDetector.prototype.parseText = function (text) {
if (!text || text === '') {
text = undefined
} else {
text = text.trim()
}
return text
}
return BombDetector
}

@@ -1,14 +0,16 @@

function Timer(file, date) {
this.file = file;
this.date = date;
this.isBomb = false;
this.updateIsBomb();
function Timer (data) {
this.file = data.file
this.date = data.date
this.text = data.text
this.isBomb = false
this.updateIsBomb()
}
Timer.prototype.updateIsBomb = function() {
Timer.prototype.updateIsBomb = function () {
if (this.date <= new Date()) {
this.isBomb = true;
this.isBomb = true
}
};
}
module.exports = Timer;
module.exports = Timer

@@ -1,21 +0,21 @@

var Timer = require('./timer');
var Timer = require('./timer')
function Timers() {
this.items = [];
function Timers () {
this.items = []
}
Timers.prototype.add = function(file, date) {
this.items.push(new Timer(file, date));
};
Timers.prototype.add = function (data) {
this.items.push(new Timer(data))
}
Timers.prototype.get = function(file, date) {
return this.items;
};
Timers.prototype.get = function () {
return this.items
}
Timers.prototype.bombs = function() {
return this.items.filter(function(item) {
return item.isBomb;
}, this);
};
Timers.prototype.bombs = function () {
return this.items.filter(function (item) {
return item.isBomb
}, this)
}
module.exports = Timers;
module.exports = Timers

@@ -9,20 +9,28 @@ /*

'use strict';
'use strict'
module.exports = function(grunt) {
var BombDetector = require('./lib/bomb-detector')(grunt);
module.exports = function (grunt) {
var BombDetector = require('./lib/bomb-detector')(grunt)
grunt.registerMultiTask('time_bomb', 'Detect time bombs in source code comments.', function() {
var bd = new BombDetector();
bd.parse(this.filesSrc);
var timers = bd.timers.get(), bombs = bd.timers.bombs();
grunt.registerMultiTask('time_bomb', 'Detect time bombs in source code comments.', function () {
var bd = new BombDetector()
bd.parse(this.filesSrc)
var timers = bd.timers.get()
var bombs = bd.timers.bombs()
var message = ''
if (timers.length === 0) {
grunt.log.write('No timers found.');
grunt.log.write('No timers found.')
} else if (timers.length > 0 && bombs.length === 0) {
grunt.log.ok('No exploded time bombs found.');
grunt.log.ok('No exploded time bombs found.')
} else if (bombs.length > 0) {
grunt.fail.warn('Exploded time bomb found in file: ' + bombs[0].file);
bombs.forEach(function (bomb) {
message = 'Exploded time bomb found in file: ' + bomb.file
if (bomb.text) {
message += ' - ' + bomb.text
}
grunt.fail.warn(message)
}, this)
}
});
};
})
}

@@ -0,31 +1,29 @@

// @timer 2100-01-01
// @timer 1990-01-01
function past() {
console.log('past');
}
// @timer 2016-01-01
function presence() {
console.log('presence');
}
// @timer: 1990-01-01
// @timer 2100-01-01
function future() {
console.log('future');
}
// @Timer 1990-01-01
// first line
// @timer 2100-01-02
// @timer 1990-01-01
// third line
/**
* A comment
*
* @timer 2100-01-03
* @timer 1990-01-01
*/
// @timer 2100-01-04
// @timer: 2100-01-04
// @Timer 2100-01-05
// @timer 1990-01-01 Text
// @timerr 2100-01-01
// @timer 1990-01-01 12:00
// @timer 1990-01-01 12:00 Text
// @timer 1990-01-01 12:12:12 Text
// @timer 1990-01-01 12:00 Text Text
// @timerr 1990-01-01

@@ -37,3 +37,3 @@ 'use strict';

defaults: function(test) {
test.expect(2);
test.expect(10);

@@ -43,7 +43,25 @@ var timers = this.bd.timers.get();

test.equal(timers.length, 8, 'should detect all timers');
test.equal(bombs.length, 2, 'should detect all bombs');
test.equal(timers.length, 11, 'should detect all timers');
test.equal(bombs.length, 10, 'should detect all bombs');
// @timer 2100-01-01
test.equal(bombs[0].date.getTime(), new Date('1990-01-01T00:00:00Z').getTime(), 'should detect date');
test.equal(bombs[0].text, undefined, 'should detect date');
// @timer 1990-01-01 Text
test.equal(bombs[5].text, 'Text', 'should detect text');
// @timer 1990-01-01 12:00
test.equal(bombs[6].date.getTime(), new Date('1990-01-01T12:00:00Z').getTime(), 'should detect time');
// @timer 1990-01-01 12:12:12 Text
test.equal(bombs[8].date.getTime(), new Date('1990-01-01T12:12:12Z').getTime(), 'should detect time with minutes');
test.equal(bombs[8].text, 'Text', 'should detect text');
// @timer 1990-01-01 12:00 Text Text
test.equal(bombs[9].date.getTime(), new Date('1990-01-01T12:00:00Z').getTime(), 'should detect time');
test.equal(bombs[9].text, 'Text Text', 'should detect text');
test.done();
}
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc