<commit_before>'use strict';

var assert = require('assert');

describe('linter', function () {
    var linter = require('../../lib/linter');

    describe('lint', function () {
        it('should return array of errors', function () {
            var source = '.foo{ color:red; }\n';
            var path = 'test.less';
            var actual;

            var config = {
                spaceAfterPropertyColon: {
                    enabled: true,
                    style: 'one_space'
                },
                spaceBeforeBrace: {
                    enabled: true,
                    style: 'one_space'
                }
            };

            actual = linter.lint(source, path, config);

            assert.ok(actual.length === 2);
        });

        it('should handle all sorts of line endings (#40)', function () {
            var source = '.foo {\r\n margin-right:10px; }\r\n';
            var path = 'test.less';
            var actual;

            var expected = [{
                column: 15,
                file: 'test.less',
                line: 2,
                linter: 'spaceAfterPropertyColon',
                message: 'Colon after property name should be followed by one space.',
                source: ' margin-right:10px; }',
                severity: 'warning'
            }];

            var config = {
                spaceAfterPropertyColon: {
                    enabled: true,
                    style: 'one_space'
                }
            };

            actual = linter.lint(source, path, config);

            assert.deepEqual(actual, expected);
        });

        it('should pass the filename to the errors list', function () {
            var source = '.foo{ color: red; }\n';
            var path = 'path/to/file.less';
            var actual;

            var expected = [{
                column: 5,
                file: 'file.less',
                line: 1,
                linter: 'spaceBeforeBrace',
                message: 'Opening curly brace should be preceded by one space.',
                source: '.foo{ color: red; }',
                severity: 'warning'
            }];

            var config = {
                spaceBeforeBrace: {
                    enabled: true,
                    style: 'one_space'
                }
            };

            actual = linter.lint(source, path, config);

            assert.deepEqual(actual, expected);
        });

        it('should expose the offending source in the errors list', function () {
            var source = '.foo{}';
            var path = 'path/to/file.less';
            var actual;

            var expected = [{
                column: 5,
                file: 'file.less',
                line: 1,
                linter: 'spaceBeforeBrace',
                message: 'Opening curly brace should be preceded by one space.',
                source: '.foo{}',
                severity: 'warning'
            }];

            var config = {
                spaceBeforeBrace: {
                    enabled: true,
                    style: 'one_space'
                }
            };

            actual = linter.lint(source, path, config);

            assert.deepEqual(actual, expected);
        });

        it('should sort results by column and line number', function () {
            var source = '[type="text"], [type=email] {\nmargin-right: 10px;\ncolor: red;\ncolor: blue;\n}';
            var path = 'path/to/file.less';
            var actual;

            var expected = [{
                column: 7,
                line: 1,
                linter: 'stringQuotes',
                message: 'Strings should use single quotes.',
                file: 'file.less',
                source: '[type="text"], [type=email] {',
                severity: 'warning'
            },
            {
                column: 22,
                line: 1,
                linter: 'attributeQuotes',
                message: 'Attribute selectors should use quotes.',
                file: 'file.less',
                source: '[type="text"], [type=email] {',
                severity: 'warning'
            },
            {
                column: 1,
                line: 3,
                linter: 'propertyOrdering',
                message: 'Property ordering is not alphabetized',
                file: 'file.less',
                source: 'color: red;',
                severity: 'warning'
            },
            {
                column: 1,
                line: 4,
                linter: 'duplicateProperty',
                message: 'Duplicate property: "color".',
                file: 'file.less',
                source: 'color: blue;',
                severity: 'warning'
            }];

            var config = {
                attributeQuotes: {
                    enabled: true
                },
                duplicateProperty: {
                    enabled: true,
                    exclude: []
                },
                propertyOrdering: {
                    enabled: true,
                    style: 'alpha'
                },
                singleLinePerProperty: false,
                stringQuotes: {
                    enabled: true,
                    style: 'single'
                }
            };

            actual = linter.lint(source, path, config);

            assert.deepEqual(actual, expected);
        });

        it('should not call disabled linters', function () {
            var source = '.foo{}';
            var path = 'test.less';
            var actual;

            var config = {
                spaceBeforeBrace: {
                    enabled: false
                }
            };

            actual = linter.lint(source, path, config);

            assert.ok(actual.length === 0);
        });

        it('should not call linter for unwanted node types', function () {
            var source = '.foo {}';
            var path = 'test.less';
            var actual;

            var config = {<commit_msg>Add linter test for shorthand disabled linters<commit_after>'use strict';

var assert = require('assert');

describe('linter', function () {
    var linter = require('../../lib/linter');

    describe('lint', function () {
        it('should return array of errors', function () {
            var source = '.foo{ color:red; }\n';
            var path = 'test.less';
            var actual;

            var config = {
                spaceAfterPropertyColon: {
                    enabled: true,
                    style: 'one_space'
                },
                spaceBeforeBrace: {
                    enabled: true,
                    style: 'one_space'
                }
            };

            actual = linter.lint(source, path, config);

            assert.ok(actual.length === 2);
        });

        it('should handle all sorts of line endings (#40)', function () {
            var source = '.foo {\r\n margin-right:10px; }\r\n';
            var path = 'test.less';
            var actual;

            var expected = [{
                column: 15,
                file: 'test.less',
                line: 2,
                linter: 'spaceAfterPropertyColon',
                message: 'Colon after property name should be followed by one space.',
                source: ' margin-right:10px; }',
                severity: 'warning'
            }];

            var config = {
                spaceAfterPropertyColon: {
                    enabled: true,
                    style: 'one_space'
                }
            };

            actual = linter.lint(source, path, config);

            assert.deepEqual(actual, expected);
        });

        it('should pass the filename to the errors list', function () {
            var source = '.foo{ color: red; }\n';
            var path = 'path/to/file.less';
            var actual;

            var expected = [{
                column: 5,
                file: 'file.less',
                line: 1,
                linter: 'spaceBeforeBrace',
                message: 'Opening curly brace should be preceded by one space.',
                source: '.foo{ color: red; }',
                severity: 'warning'
            }];

            var config = {
                spaceBeforeBrace: {
                    enabled: true,
                    style: 'one_space'
                }
            };

            actual = linter.lint(source, path, config);

            assert.deepEqual(actual, expected);
        });

        it('should expose the offending source in the errors list', function () {
            var source = '.foo{}';
            var path = 'path/to/file.less';
            var actual;

            var expected = [{
                column: 5,
                file: 'file.less',
                line: 1,
                linter: 'spaceBeforeBrace',
                message: 'Opening curly brace should be preceded by one space.',
                source: '.foo{}',
                severity: 'warning'
            }];

            var config = {
                spaceBeforeBrace: {
                    enabled: true,
                    style: 'one_space'
                }
            };

            actual = linter.lint(source, path, config);

            assert.deepEqual(actual, expected);
        });

        it('should sort results by column and line number', function () {
            var source = '[type="text"], [type=email] {\nmargin-right: 10px;\ncolor: red;\ncolor: blue;\n}';
            var path = 'path/to/file.less';
            var actual;

            var expected = [{
                column: 7,
                line: 1,
                linter: 'stringQuotes',
                message: 'Strings should use single quotes.',
                file: 'file.less',
                source: '[type="text"], [type=email] {',
                severity: 'warning'
            },
            {
                column: 22,
                line: 1,
                linter: 'attributeQuotes',
                message: 'Attribute selectors should use quotes.',
                file: 'file.less',
                source: '[type="text"], [type=email] {',
                severity: 'warning'
            },
            {
                column: 1,
                line: 3,
                linter: 'propertyOrdering',
                message: 'Property ordering is not alphabetized',
                file: 'file.less',
                source: 'color: red;',
                severity: 'warning'
            },
            {
                column: 1,
                line: 4,
                linter: 'duplicateProperty',
                message: 'Duplicate property: "color".',
                file: 'file.less',
                source: 'color: blue;',
                severity: 'warning'
            }];

            var config = {
                attributeQuotes: {
                    enabled: true
                },
                duplicateProperty: {
                    enabled: true,
                    exclude: []
                },
                propertyOrdering: {
                    enabled: true,
                    style: 'alpha'
                },
                singleLinePerProperty: false,
                stringQuotes: {
                    enabled: true,
                    style: 'single'
                }
            };

            actual = linter.lint(source, path, config);

            assert.deepEqual(actual, expected);
        });

        it('should not call disabled linters', function () {
            var source = '.foo{}';
            var path = 'test.less';
            var actual;

            var config = {
                spaceBeforeBrace: {
                    enabled: false
                }
            };

            actual = linter.lint(source, path, config);

            assert.ok(actual.length === 0);
        });

        it('should not call linters disabled via shorthand', function () {
            var source = '.foo{}';
            var path = 'test.less';
            var actual;

            var config = {
                spaceBeforeBrace: false
            };

            actual = linter.lint(source, path, config);

            assert.ok(actual.length === 0);
        });

        it('should not call linter for unwanted node types', function () {
            var source = '.foo {}';
            var path = 'test.less';
            var actual;

            var config = {
{'fraction_non_alphanumeric': 0.11053943243025967, 'fraction_numerical': 0.004260792668220918, 'mean_word_length': 1.0767946577629381, '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': '3353667', 'n_tokens_mistral': 3188, 'n_tokens_neox': 2879, 'n_words': 806}