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

var abcLint = require("../lib/abc-lint");

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

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

    return errors;
}

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

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

    it("should fail when properties are out of order", function() {
        var lessCode = [
            "a {",
            "   margin: 0;",
            "   background-color: black;",
            "   color: white;",
            "}",
        ].join("\n");

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

        // Grab the line number from the error message
        var lineNo = errors[0].split(" ").slice(-1)[0];
        assert(Number(lineNo) === 3);
    });

    it("should pass for declarations with a single property", function() {
        var lessCode = [
            "p,",
            "a {",
            "   color: white;",
            "}",
        ].join("\n");

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

    it("should pass when properties are nested and in order", function() {
        var lessCode = [
            "a {",
            "   background-color: black;",
            "   color: white;",
            "   margin: 0;",
            "",
            "   p {",
            "       color: red;",
            "       padding-top: 5px;",
            "   }",
            "}",
        ].join("\n");

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

    it("should fail when properties are nested and out of order", function() {
        var lessCode = [
            "a {",
            "   background-color: black;",
            "   color: white;",
            "   margin: 0;",
            "",
            "   p {",
            "       color: red;",
            "       background-color: green;",
            "   }",
            "}",
        ].join("\n");

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

        // Grab the line number from the error message
        var lineNo = errors[0].split(" ").slice(-1)[0];
        assert(Number(lineNo) === 8);
    });

    // TODO: Consider variables as well, they should be above all declarations
    it("should ignore variables", function() {
        var lessCode = [
            "a {",
            "   width: 40px;",
            "   @abc: 400;",
            "   color: white;",
            "}",
        ].join("\n");

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

        // Grab the line number from the error message
        var lineNo = errors[0].split(" ").slice(-1)[0];
        assert(Number(lineNo) === 4);
    })
});
<commit_msg>use parseInt() instead of Number()<commit_after>/**
 * Tests the ABC linter
 */
var assert = require("assert");
var less = require("less");

var abcLint = require("../lib/abc-lint");

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

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

    return errors;
}

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

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

    it("should fail when properties are out of order", function() {
        var lessCode = [
            "a {",
            "   margin: 0;",
            "   background-color: black;",
            "   color: white;",
            "}",
        ].join("\n");

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

        // Grab the line number from the error message
        var lineNo = parseInt(errors[0].split(" ").slice(-1)[0]);
        assert(lineNo === 3);
    });

    it("should pass for declarations with a single property", function() {
        var lessCode = [
            "p,",
            "a {",
            "   color: white;",
            "}",
        ].join("\n");

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

    it("should pass when properties are nested and in order", function() {
        var lessCode = [
            "a {",
            "   background-color: black;",
            "   color: white;",
            "   margin: 0;",
            "",
            "   p {",
            "       color: red;",
            "       padding-top: 5px;",
            "   }",
            "}",
        ].join("\n");

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

    it("should fail when properties are nested and out of order", function() {
        var lessCode = [
            "a {",
            "   background-color: black;",
            "   color: white;",
            "   margin: 0;",
            "",
            "   p {",
            "       color: red;",
            "       background-color: green;",
            "   }",
            "}",
        ].join("\n");

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

        // Grab the line number from the error message
        var lineNo = parseInt(errors[0].split(" ").slice(-1)[0]);
        assert(lineNo === 8);
    });

    // TODO: Consider variables as well, they should be above all declarations
    it("should ignore variables", function() {
        var lessCode = [
            "a {",
            "   width: 40px;",
            "   @abc: 400;",
            "   color: white;",
            "}",
        ].join("\n");

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

        // Grab the line number from the error message
        var lineNo = parseInt(errors[0].split(" ").slice(-1)[0]);
        assert(lineNo === 4);
    })
});

{'fraction_non_alphanumeric': 0.16015924054509265, 'fraction_numerical': 0.00857449088960343, 'mean_word_length': 1.4902783072817385, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7612595', 'n_tokens_mistral': 1904, 'n_tokens_neox': 1827, 'n_words': 484}