Skip to content

Commit

Permalink
update eslint. lint, fix unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschlinkert committed May 21, 2024
1 parent 415d660 commit 88f1429
Show file tree
Hide file tree
Showing 23 changed files with 593 additions and 499 deletions.
189 changes: 137 additions & 52 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"extends": [
"eslint:recommended"
],
"root": true,
"extends": "eslint:recommended",

"env": {
"browser": false,
"es6": true,
"node": true,
"mocha": true
"mocha": true,
"node": true
},

"parserOptions":{
Expand All @@ -27,104 +26,190 @@

"rules": {
"accessor-pairs": 2,
"arrow-spacing": [2, { "before": true, "after": true }],
"block-spacing": [2, "always"],
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
"comma-dangle": [2, "never"],
"comma-spacing": [2, { "before": false, "after": true }],
"comma-style": [2, "last"],
"array-bracket-newline": [1, "consistent"],
"array-bracket-spacing": [1, "never"],
"array-callback-return": 1,
"array-element-newline": [1, "consistent"],
"arrow-body-style": 0,
"arrow-parens": [1, "as-needed"],
"arrow-spacing": [1, { "before": true, "after": true }],
"block-scoped-var": 1,
"block-spacing": [1, "always"],
"brace-style": [1, "1tbs", { "allowSingleLine": true }],
"callback-return": 0,
"camelcase": [0, { "allow": [] }],
"capitalized-comments": 0,
"class-methods-use-this": 0,
"comma-dangle": [1, "never"],
"comma-spacing": [1, { "before": false, "after": true }],
"comma-style": [1, "last"],
"computed-property-spacing": 1,
"consistent-return": 0,
"consistent-this": 1,
"constructor-super": 2,
"curly": [2, "multi-line"],
"dot-location": [2, "property"],
"eol-last": 2,
"eqeqeq": [2, "allow-null"],
"generator-star-spacing": [2, { "before": true, "after": true }],
"handle-callback-err": [2, "^(err|error)$" ],
"indent": [2, 2, { "SwitchCase": 1 }],
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"keyword-spacing": [2, { "before": true, "after": true }],
"new-cap": [2, { "newIsCap": true, "capIsNew": false }],
"curly": [1, "multi-line", "consistent"],
"default-case": 1,
"dot-location": [1, "property"],
"dot-notation": 1,
"eol-last": 1,
"eqeqeq": [1, "allow-null"],
"for-direction": 1,
"func-call-spacing": 2,
"generator-star-spacing": [1, { "before": true, "after": true }],
"handle-callback-err": [2, "^(err|error)$"],
"indent": [1, 2, { "SwitchCase": 1 }],
"key-spacing": [1, { "beforeColon": false, "afterColon": true }],
"keyword-spacing": [1, { "before": true, "after": true }],
"linebreak-style": [1, "unix"],
"new-cap": [1, { "newIsCap": true, "capIsNew": false }],
"new-parens": 2,
"no-array-constructor": 2,
"no-alert": 1,
"no-array-constructor": 1,
"no-async-promise-executor": 1,
"no-caller": 2,
"no-case-declarations": 1,
"no-class-assign": 2,
"no-cond-assign": 2,
"no-const-assign": 2,
"no-constant-condition": [1, { "checkLoops": false }],
"no-control-regex": 2,
"no-debugger": 2,
"no-delete-var": 2,
"no-dupe-args": 2,
"no-dupe-class-members": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-duplicate-imports": 0,
"no-else-return": 0,
"no-empty-character-class": 2,
"no-eval": 2,
"no-empty-function": 0,
"no-empty-pattern": 0,
"no-empty": [1, { "allowEmptyCatch": true }],
"no-eval": 0,
"no-ex-assign": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-extra-boolean-cast": 2,
"no-extra-parens": [2, "functions"],
"no-extra-bind": 1,
"no-extra-boolean-cast": 1,
"no-extra-label": 1,
"no-extra-parens": [1, "all",
{
"conditionalAssign": false,
"returnAssign": false,
"nestedBinaryExpressions": false,
"ignoreJSX": "multi-line",
"enforceForArrowConditionals": false
}
],
"no-extra-semi": 1,
"no-fallthrough": 2,
"no-floating-decimal": 2,
"no-func-assign": 2,
"no-global-assign": 2,
"no-implicit-coercion": 2,
"no-implicit-globals": 1,
"no-implied-eval": 2,
"no-inner-declarations": [2, "functions"],
"no-inner-declarations": [1, "functions"],
"no-invalid-regexp": 2,
"no-invalid-this": 1,
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-lonely-if": 2,
"no-loop-func": 1,
"no-mixed-requires": 1,
"no-mixed-spaces-and-tabs": 2,
"no-multi-spaces": 2,
"no-multi-assign": 0,
"no-multi-spaces": 1,
"no-multi-str": 2,
"no-multiple-empty-lines": [2, { "max": 1 }],
"no-native-reassign": 0,
"no-multiple-empty-lines": [1, { "max": 1 }],
"no-native-reassign": 2,
"no-negated-condition": 0,
"no-negated-in-lhs": 2,
"no-new": 2,
"no-new-func": 2,
"no-new-object": 2,
"no-new-require": 2,
"no-new-symbol": 1,
"no-new-wrappers": 2,
"no-new": 1,
"no-obj-calls": 2,
"no-octal": 2,
"no-octal-escape": 2,
"no-proto": 0,
"no-octal": 2,
"no-path-concat": 1,
"no-proto": 2,
"no-prototype-builtins": 0,
"no-redeclare": 2,
"no-regex-spaces": 2,
"no-return-assign": 2,
"no-self-compare": 2,
"no-restricted-globals": 2,
"no-return-assign": 1,
"no-return-await": 2,
"no-script-url": 1,
"no-self-assign": 1,
"no-self-compare": 1,
"no-sequences": 2,
"no-shadow-restricted-names": 2,
"no-shadow": 0,
"no-spaced-func": 2,
"no-sparse-arrays": 2,
"no-template-curly-in-string": 0,
"no-this-before-super": 2,
"no-throw-literal": 2,
"no-trailing-spaces": 0,
"no-undef": 2,
"no-trailing-spaces": 1,
"no-undef-init": 2,
"no-undef": 2,
"no-unexpected-multiline": 2,
"no-unneeded-ternary": [2, { "defaultAssignment": false }],
"no-unneeded-ternary": [1, { "defaultAssignment": false }],
"no-unreachable-loop": 1,
"no-unreachable": 2,
"no-unused-vars": [2, { "vars": "all", "args": "none" }],
"no-useless-call": 0,
"no-unsafe-assignment": 0,
"no-unsafe-call": 0,
"no-unsafe-finally": 2,
"no-unsafe-member-access": 0,
"no-unsafe-negation": 2,
"no-unsafe-optional-chaining": 0,
"no-unsafe-return": 0,
"no-unused-expressions": 2,
"no-unused-vars": [1, { "vars": "all", "args": "after-used" }],
"no-use-before-define": 0,
"no-useless-call": 2,
"no-useless-catch": 0,
"no-useless-escape": 0,
"no-useless-rename": 1,
"no-useless-return": 1,
"no-var": 1,
"no-void": 1,
"no-warning-comments": 0,
"no-with": 2,
"one-var": [0, { "initialized": "never" }],
"object-curly-spacing": [1, "always", { "objectsInObjects": true }],
"object-shorthand": 1,
"one-var": [1, { "initialized": "never" }],
"operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }],
"padded-blocks": [0, "never"],
"quotes": [2, "single", "avoid-escape"],
"padded-blocks": [1, { "switches": "never" }],
"prefer-const": [1, { "destructuring": "all", "ignoreReadBeforeAssign": false }],
"prefer-promise-reject-errors": 1,
"quotes": [1, "single", "avoid-escape"],
"radix": 2,
"semi": [2, "always"],
"semi-spacing": [2, { "before": false, "after": true }],
"space-before-blocks": [2, "always"],
"space-before-function-paren": [2, "never"],
"space-in-parens": [2, "never"],
"space-infix-ops": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"rest-spread-spacing": 1,
"semi-spacing": [1, { "before": false, "after": true }],
"semi-style": 1,
"semi": [1, "always"],
"space-before-blocks": [1, "always"],
"space-before-function-paren": [1, { "anonymous": "never", "named": "never", "asyncArrow": "always" }],
"space-in-parens": [1, "never"],
"space-infix-ops": 1,
"space-unary-ops": [1, { "words": true, "nonwords": false }],
"spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }],
"strict": 2,
"switch-colon-spacing": 1,
"symbol-description": 1,
"template-curly-spacing": [2, "never"],
"template-tag-spacing": [2, "never"],
"unicode-bom": 1,
"use-isnan": 2,
"valid-jsdoc": 1,
"valid-typeof": 2,
"wrap-iife": [2, "any"],
"yoda": [2, "never"]
"wrap-iife": [1, "any"],
"yoda": [1, "never"]
}
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014-2018, Jon Schlinkert.
Copyright (c) 2014-present, Jon Schlinkert.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion bench/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const braces = require('..');
*/

const cycle = (e, newline) => {
process.stdout.write(`\u001b[G ${e.target}${newline ? `\n` : ''}`);
process.stdout.write(`\u001b[G ${e.target}${newline ? '\n' : ''}`);
};

const bench = (name, options) => {
Expand Down
3 changes: 1 addition & 2 deletions examples/expand.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

const colors = require('ansi-colors');
const parse = require('./parse');
const color = (arr, c) => arr.map(s => c(s)).join(', ');
const cp = require('child_process');
const braces = input => {
Expand All @@ -19,6 +18,6 @@ const braces = input => {
const fixture = 'a{,b}c';
console.log();
console.log(' FIXTURE:', colors.magenta(fixture));
console.log(' ACTUAL:', color(expand(parse(fixture)), colors.yellow));
// console.log(' ACTUAL:', color(expand(parse(fixture)), colors.yellow));
console.log('EXPECTED:', color(braces(fixture), colors.blue));
console.log();
2 changes: 1 addition & 1 deletion examples/option-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ console.log(alpha);
//=> [ 'x/foo/a-0/y', 'x/foo/b-1/y', 'x/foo/c-2/y', 'x/foo/d-3/y', 'x/foo/e-4/y' ]

const numeric = braces.expand('{1..5}', {
transform(value, index) {
transform(value) {
return 'foo/' + value * 2;
}
});
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const braces = (input, options = {}) => {
let output = [];

if (Array.isArray(input)) {
for (let pattern of input) {
let result = braces.create(pattern, options);
for (const pattern of input) {
const result = braces.create(pattern, options);
if (Array.isArray(result)) {
output.push(...result);
} else {
Expand Down Expand Up @@ -158,7 +158,7 @@ braces.create = (input, options = {}) => {
return [input];
}

return options.expand !== true
return options.expand !== true
? braces.compile(input, options)
: braces.expand(input, options);
};
Expand Down
25 changes: 14 additions & 11 deletions lib/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,53 @@ const fill = require('fill-range');
const utils = require('./utils');

const compile = (ast, options = {}) => {
let walk = (node, parent = {}) => {
let invalidBlock = utils.isInvalidBrace(parent);
let invalidNode = node.invalid === true && options.escapeInvalid === true;
let invalid = invalidBlock === true || invalidNode === true;
let prefix = options.escapeInvalid === true ? '\\' : '';
const walk = (node, parent = {}) => {
const invalidBlock = utils.isInvalidBrace(parent);
const invalidNode = node.invalid === true && options.escapeInvalid === true;
const invalid = invalidBlock === true || invalidNode === true;
const prefix = options.escapeInvalid === true ? '\\' : '';
let output = '';

if (node.isOpen === true) {
return prefix + node.value;
}

if (node.isClose === true) {
console.log('node.isClose', prefix, node.value);
return prefix + node.value;
}

if (node.type === 'open') {
return invalid ? (prefix + node.value) : '(';
return invalid ? prefix + node.value : '(';
}

if (node.type === 'close') {
return invalid ? (prefix + node.value) : ')';
return invalid ? prefix + node.value : ')';
}

if (node.type === 'comma') {
return node.prev.type === 'comma' ? '' : (invalid ? node.value : '|');
return node.prev.type === 'comma' ? '' : invalid ? node.value : '|';
}

if (node.value) {
return node.value;
}

if (node.nodes && node.ranges > 0) {
let args = utils.reduce(node.nodes);
let range = fill(...args, { ...options, wrap: false, toRegex: true });
const args = utils.reduce(node.nodes);
const range = fill(...args, { ...options, wrap: false, toRegex: true, strictZeros: true });

if (range.length !== 0) {
return args.length > 1 && range.length > 1 ? `(${range})` : range;
}
}

if (node.nodes) {
for (let child of node.nodes) {
for (const child of node.nodes) {
output += walk(child, node);
}
}

return output;
};

Expand Down
Loading

0 comments on commit 88f1429

Please sign in to comment.