Skip to content

Commit

Permalink
Merge pull request #115 from hildjj/eslint-config
Browse files Browse the repository at this point in the history
Move to shared eslint-config.
  • Loading branch information
hildjj authored Apr 25, 2021
2 parents 375a8f1 + 81eeebd commit b3551fa
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 700 deletions.
657 changes: 2 additions & 655 deletions .eslintrc.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions bin/peggy
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

"use strict";

let fs = require("fs");
let path = require("path");
let peg = require("../lib/peg");
const fs = require("fs");
const path = require("path");
const peg = require("../lib/peg");

// Helpers

Expand Down Expand Up @@ -82,7 +82,7 @@ function trim(s) {

// Arguments

let args = process.argv.slice(2); // Trim "node" and the script path.
const args = process.argv.slice(2); // Trim "node" and the script path.

function isOption(arg) {
return (/^-.+/).test(arg);
Expand All @@ -105,7 +105,7 @@ function readStream(inputStream, callback) {
let inputFile = null;
let outputFile = null;

let options = {
const options = {
// Path to the grammar file
grammarSource: null,
cache: false,
Expand Down Expand Up @@ -146,7 +146,7 @@ while (args.length > 0 && isOption(args[0])) {
abort("Missing parameter of the -d/--dependency option.");
}
if (args[0].indexOf(":") !== -1) {
let parts = args[0].split(":");
const parts = args[0].split(":");
options.dependencies[parts[0]] = parts[1];
} else {
options.dependencies[args[0]] = args[0];
Expand Down
20 changes: 10 additions & 10 deletions lib/compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function processOptions(options, defaults) {
const compiler = {
// AST node visitor builder. Useful mainly for plugins which manipulate the
// AST.
visitor: visitor,
visitor,

// Compiler passes.
//
Expand All @@ -39,19 +39,19 @@ const compiler = {
// |peg.GrammarError|.
passes: {
check: {
reportUndefinedRules: reportUndefinedRules,
reportDuplicateRules: reportDuplicateRules,
reportDuplicateLabels: reportDuplicateLabels,
reportInfiniteRecursion: reportInfiniteRecursion,
reportInfiniteRepetition: reportInfiniteRepetition,
reportIncorrectPlucking: reportIncorrectPlucking
reportUndefinedRules,
reportDuplicateRules,
reportDuplicateLabels,
reportInfiniteRecursion,
reportInfiniteRepetition,
reportIncorrectPlucking
},
transform: {
removeProxyRules: removeProxyRules
removeProxyRules
},
generate: {
generateBytecode: generateBytecode,
generateJS: generateJS
generateBytecode,
generateJS
}
},

Expand Down
4 changes: 2 additions & 2 deletions lib/compiler/passes/generate-bytecode.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ function generateBytecode(ast) {
|| node.expression.elements.length === 0;
const expressionCode = generate(node.expression, {
sp: context.sp + (emitCall ? 1 : 0),
env: env,
env,
action: node
});
const functionIndex = addFunctionConst(Object.keys(env), node.code);
Expand Down Expand Up @@ -465,7 +465,7 @@ function generateBytecode(ast) {

return generate(node.expression, {
sp: context.sp,
env: env,
env,
action: null
});
},
Expand Down
6 changes: 3 additions & 3 deletions lib/peg.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const VERSION = require("./version");
const peg = {
// Peggy version (filled in by /tools/release).
VERSION,
GrammarError: GrammarError,
parser: parser,
compiler: compiler,
GrammarError,
parser,
compiler,

// Generates a parser from a specified grammar and returns it.
//
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"pretest": "npm run parser",
"test": "npm run test:bare",
"test:bare": "mocha --recursive test --exclude test/browser.stub.js --reporter min",
"lint": "eslint . --ext .js",
"lint": "eslint . --ext .js bin/peggy",
"benchmark": "./benchmark/run",
"build": "npm run browser:build && npm run benchmark:build && npm run test:build",
"browser:clean": "rm -rf browser/",
Expand All @@ -35,10 +35,11 @@
"devDependencies": {
"@babel/core": "^7.13.16",
"@babel/preset-env": "^7.13.15",
"@peggyjs/eslint-config": "^0.0.1",
"babelify": "10.0.0",
"browserify": "17.0.0",
"chai": "4.3.4",
"eslint": "^7.24.0",
"eslint": "^7.25.0",
"express": "4.17.1",
"mocha": "^8.3.2",
"morgan": "1.10.0",
Expand Down
2 changes: 1 addition & 1 deletion test/api/generated-parser-api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ describe("generated parser API", function() {

const tracer = { trace: sinon.spy() };

parser.parse("b", { tracer: tracer });
parser.parse("b", { tracer });

expect(tracer.trace.callCount).to.equal(events.length);
events.forEach((event, index) => {
Expand Down
6 changes: 3 additions & 3 deletions test/api/pegjs-api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe("Peggy API", function() {
const parser = peg.generate(grammar);
const tracer = { trace: sinon.spy() };

parser.parse("a", { tracer: tracer });
parser.parse("a", { tracer });

expect(tracer.trace.called).to.equal(false);
});
Expand All @@ -140,7 +140,7 @@ describe("Peggy API", function() {
const parser = peg.generate(grammar, { trace: false });
const tracer = { trace: sinon.spy() };

parser.parse("a", { tracer: tracer });
parser.parse("a", { tracer });

expect(tracer.trace.called).to.equal(false);
});
Expand All @@ -151,7 +151,7 @@ describe("Peggy API", function() {
const parser = peg.generate(grammar, { trace: true });
const tracer = { trace: sinon.spy() };

parser.parse("a", { tracer: tracer });
parser.parse("a", { tracer });

expect(tracer.trace.called).to.equal(true);
});
Expand Down
2 changes: 1 addition & 1 deletion test/api/plugin-api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("plugin API", function() {
{ use() { pluginsUsed[2] = true; } }
];

peg.generate(grammar, { plugins: plugins });
peg.generate(grammar, { plugins });

expect(pluginsUsed).to.deep.equal([true, true, true]);
});
Expand Down
4 changes: 2 additions & 2 deletions test/unit/compiler/passes/generate-bytecode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ const expect = chai.expect;
describe("compiler pass |generateBytecode|", function() {
function bytecodeDetails(bytecode) {
return {
rules: [{ bytecode: bytecode }]
rules: [{ bytecode }]
};
}

function constsDetails(consts) { return { consts: consts }; }
function constsDetails(consts) { return { consts }; }

describe("for grammar", function() {
it("generates correct bytecode", function() {
Expand Down
30 changes: 15 additions & 15 deletions test/unit/parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,28 @@ describe("Peggy grammar parser", function() {
type: "grammar",
topLevelInitializer: null,
initializer: null,
rules: [{ type: "rule", name: "start", expression: expression }]
rules: [{ type: "rule", name: "start", expression }]
};
}

function actionGrammar(code) {
return oneRuleGrammar(
{ type: "action", expression: literalAbcd, code: code }
{ type: "action", expression: literalAbcd, code }
);
}

function literalGrammar(value, ignoreCase) {
return oneRuleGrammar(
{ type: "literal", value: value, ignoreCase: ignoreCase }
{ type: "literal", value, ignoreCase }
);
}

function classGrammar(parts, inverted, ignoreCase) {
return oneRuleGrammar({
type: "class",
parts: parts,
inverted: inverted,
ignoreCase: ignoreCase
parts,
inverted,
ignoreCase
});
}

Expand All @@ -98,7 +98,7 @@ describe("Peggy grammar parser", function() {
}

function ruleRefGrammar(name) {
return oneRuleGrammar({ type: "rule_ref", name: name });
return oneRuleGrammar({ type: "rule_ref", name });
}

const trivialGrammar = literalGrammar("abcd", false);
Expand Down Expand Up @@ -239,27 +239,27 @@ describe("Peggy grammar parser", function() {
{ type: "grammar", topLevelInitializer: null, initializer: null, rules: [ruleA, ruleB, ruleC] }
);
expect("\n{ code };\na = 'abcd';\n").to.parseAs(
{ type: "grammar", topLevelInitializer: null, initializer: initializer, rules: [ruleA] }
{ type: "grammar", topLevelInitializer: null, initializer, rules: [ruleA] }
);
expect("\n{{ top level code }};\na = 'abcd';\n").to.parseAs(
{ type: "grammar", topLevelInitializer: topLevelInitializer, initializer: null, rules: [ruleA] }
{ type: "grammar", topLevelInitializer, initializer: null, rules: [ruleA] }
);
expect("\n{{ top level code }};\n{ code };\na = 'abcd';\n").to.parseAs(
{ type: "grammar", topLevelInitializer: topLevelInitializer, initializer: initializer, rules: [ruleA] }
{ type: "grammar", topLevelInitializer, initializer, rules: [ruleA] }
);
});

// Canonical Top-Level Initializer is "{ top level code }".
it("parses Top-Level Initializer", function() {
expect("{{ top level code }};start = 'abcd'").to.parseAs(
{ type: "grammar", topLevelInitializer: topLevelInitializer, initializer: null, rules: [ruleStart] }
{ type: "grammar", topLevelInitializer, initializer: null, rules: [ruleStart] }
);
});

// Canonical Initializer is "{ code }".
it("parses Initializer", function() {
expect("{ code };start = 'abcd'").to.parseAs(
{ type: "grammar", topLevelInitializer: null, initializer: initializer, rules: [ruleStart] }
{ type: "grammar", topLevelInitializer: null, initializer, rules: [ruleStart] }
);
});

Expand Down Expand Up @@ -323,15 +323,15 @@ describe("Peggy grammar parser", function() {
function $S(...elements) {
return oneRuleGrammar({
type: "sequence",
elements: elements,
elements,
});
}
function $P(label, expression) {
return {
type: "labeled",
pick: true,
label: label,
expression: expression,
label,
expression,
};
}

Expand Down

0 comments on commit b3551fa

Please sign in to comment.