<commit_before>/**
 * Tests the nesting linter.
 */
var assert = require("assert");
var less = require("less");

var nestingLint = require("../lib/nesting-lint");

// Run the nesting linter on a given snippet of Less code
function lintCode(code) {
    var errors = [];

    less.parse(code, function(err, ast) {
        nestingLint(code, ast, function(err) {
            errors.push(err);
        });
    });

    return errors;
}

describe("Nesting linter", function() {
    it("should pass for single rules", function() {
        var lessCode = [
            "a {",
            "   background-color: black;",
            "   color: white;",
            "   margin: 0;",
            "}",
        ].join("\n");

        var errors = lintCode(lessCode);
        assert(errors.length === 0);
    });

    it("should pass for single-nested rules", function() {
        var lessCode = [
            "a {",
            "   background-color: black;",
            "   color: white;",
            "   margin: 0;",
            "",
            "   &:hover {",
            "       color: red;",
            "   }",
            "}",
        ].join("\n");

        var errors = lintCode(lessCode);
        assert(errors.length === 0);
    });

    it("should pass for twice-nested rules", function() {
        var lessCode = [
            "a {",
            "   background-color: black;",
            "   color: white;",
            "   margin: 0;",
            "",
            "   &:hover {",
            "       color: red;",
            "",
            "       &.disabled {",
            "           color: gray;",
            "       }",
            "   }",
            "}",
        ].join("\n");

        var errors = lintCode(lessCode);
        assert(errors.length === 0);
    });

    it("should pass for three-times-nested rules", function() {
        var lessCode = [
            "a {",
            "   background-color: black;",
            "   color: white;",
            "   margin: 0;",
            "",
            "   &:hover {",
            "       color: red;",
            "",
            "       &.disabled {",
            "           color: gray;",
            "",
            "           &.main {",
            "               font-weight: bold;",
            "           }",
            "       }",
            "   }",
            "}",
        ].join("\n");

        var errors = lintCode(lessCode);
        assert(errors.length === 0);
    });

    it("should fail for four-times-nested rules", function() {
        var lessCode = [
            "a {",
            "   background-color: black;",
            "   color: white;",
            "   margin: 0;",
            "",
            "   &:hover {",
            "       color: red;",
            "",
            "       &.disabled {",
            "           color: gray;",
            "",
            "           &.main {",
            "               font-weight: bold;",
            "",
            "               i,",
            "               em {",
            "                   font-weight: 200;",
            "               }",
            "",
            "               span {}",
            "           }",
            "       }",
            "   }",
            "}",
        ].join("\n");

        var errors = lintCode(lessCode);
        assert(errors.length === 2);

        // Grab the line numbers from the error messages
        var lineNo;

        lineNo = errors[0].split(" ").slice(-1)[0];
        assert(Number(lineNo) === 15);

        var lineNo = errors[1].split(" ").slice(-1)[0];
        assert(Number(lineNo) === 20);
    });
});<commit_msg>added a unit test for multiple violations<commit_after>/**
 * Tests the nesting linter.
 */
var assert = require("assert");
var less = require("less");

var nestingLint = require("../lib/nesting-lint");

// Run the nesting linter on a given snippet of Less code
function lintCode(code) {
    var errors = [];

    less.parse(code, function(err, ast) {
        nestingLint(code, ast, function(err) {
            errors.push(err);
        });
    });

    return errors;
}

describe("Nesting linter", function() {
    it("should pass for single rules", function() {
        var lessCode = [
            "a {",
            "   background-color: black;",
            "   color: white;",
            "   margin: 0;",
            "}",
        ].join("\n");

        var errors = lintCode(lessCode);
        assert(errors.length === 0);
    });

    it("should pass for single-nested rules", function() {
        var lessCode = [
            "a {",
            "   background-color: black;",
            "   color: white;",
            "   margin: 0;",
            "",
            "   &:hover {",
            "       color: red;",
            "   }",
            "}",
        ].join("\n");

        var errors = lintCode(lessCode);
        assert(errors.length === 0);
    });

    it("should pass for twice-nested rules", function() {
        var lessCode = [
            "a {",
            "   background-color: black;",
            "   color: white;",
            "   margin: 0;",
            "",
            "   &:hover {",
            "       color: red;",
            "",
            "       &.disabled {",
            "           color: gray;",
            "       }",
            "   }",
            "}",
        ].join("\n");

        var errors = lintCode(lessCode);
        assert(errors.length === 0);
    });

    it("should pass for three-times-nested rules", function() {
        var lessCode = [
            "a {",
            "   background-color: black;",
            "   color: white;",
            "   margin: 0;",
            "",
            "   &:hover {",
            "       color: red;",
            "",
            "       &.disabled {",
            "           color: gray;",
            "",
            "           &.main {",
            "               font-weight: bold;",
            "           }",
            "       }",
            "   }",
            "}",
        ].join("\n");

        var errors = lintCode(lessCode);
        assert(errors.length === 0);
    });

    it("should fail for four-times-nested rules", function() {
        var lessCode = [
            "a {",
            "   background-color: black;",
            "   color: white;",
            "   margin: 0;",
            "",
            "   &:hover {",
            "       color: red;",
            "",
            "       &.disabled {",
            "           color: gray;",
            "",
            "           &.main {",
            "               font-weight: bold;",
            "",
            "               i,",
            "               em {",
            "                   font-weight: 200;",
            "               }",
            "",
            "               span {}",
            "           }",
            "       }",
            "   }",
            "}",
        ].join("\n");

        var errors = lintCode(lessCode);
        assert(errors.length === 2);

        // Grab the line numbers from the error messages
        var lineNos = errors.map(function(error) {
            return parseInt(error.split(" ").slice(-1)[0]);
        });

        assert(lineNos[0] === 15);
        assert(lineNos[1] === 20);
    });

    it("should fail multiple times when exceeding the limit", function() {
        var lessCode = [
            "a {",
            "   & + a {",
            "       & + a {",
            "           & + a {",
            "               & + a {",   // Too far, begin failing here
            "                   & + a {",
            "                       & + a {",
            "                           color: red;",
            "                       }",
            "                   }",
            "               }",
            "           }",
            "       }",
            "   }",
            "}",
        ].join("\n");

        var errors = lintCode(lessCode);
        assert(errors.length === 3);

        // Grab the line numbers from the error messages
        var lineNos = errors.map(function(error) {
            return parseInt(error.split(" ").slice(-1)[0]);
        });

        assert(lineNos[0] === 5);
        assert(lineNos[1] === 6);
        assert(lineNos[2] === 7);
    });
});
{'fraction_non_alphanumeric': 0.1624683620585754, 'fraction_numerical': 0.006387851030492949, 'mean_word_length': 0.9894509709901702, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4971042', 'n_tokens_mistral': 2320, 'n_tokens_neox': 2221, 'n_words': 452}