ESLINT TIME BOMB

WHO AM I? 

Worst hangover I have ever had

ESLINT + AST

AST

(Abstract Syntax Tree)

module.exports = {
    rules: {
        "time-bomb": context =>
        ({
            Program(node) {
                // do something here with the node
              }
        })
    }

};
module.exports = {
    rules: {
        "time-bomb": context =>
        ({
            Program(node) {
                node.comments.forEach((comment) => {
                    console.log(comment.value);
                  });
              }
        })
    }

};
const regex = /TODO: .* - [0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9]/;

module.exports = {
    rules: {
        "time-bomb": context =>
        ({
            Program(node) {
                node.comments.forEach((comment) => {
                  const matches = comment.value.match(regex);
                  if (matches && matches.length > 0) {
                    const dueDate = new Date(comment.value.slice(
                        comment.value.length - 10
                    ));
                    const today = new Date();
                    
                    if (today.valueOf() > dueDate.valueOf()) {
                        console.log('Comment out of date')
                    }
                  }
                });
              }
        })
    }

};
const regex = /TODO: .* - [0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9]/;

module.exports = {
    rules: {
        "time-bomb": context =>
        ({
            Program(node) {
                node.comments.forEach((comment) => {
                  const matches = comment.value.match(regex);
                  if (matches && matches.length > 0) {
                    const dueDate = new Date(comment.value.slice(
                        comment.value.length - 10
                    ));
                    const today = new Date();
                    
                    if (today.valueOf() > dueDate.valueOf()) {
                        context.report({
                            node,
                            message: `TODO past due date: was due ${dueDate}`
                        });
                    }
                  }
                });
              }
        })
    }

};
...
plugins: [
    "time-bomb"
]
...

rules: {
    "time-bomb/time-bomb" : ["error"],
}

NICD 2021 - eslint time bomb

By Chris Laughlin

NICD 2021 - eslint time bomb

  • 163