Skip to content

Change var to const or let #608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@
"space-infix-ops": 1,
"valid-typeof": 2,
"vars-on-top": 0,
"wrap-iife": [2, "inside"]
"wrap-iife": [2, "inside"],
"prefer-const": ["error", {
"destructuring": "any",
"ignoreReadBeforeAssign": false
}]
}
}
48 changes: 24 additions & 24 deletions core/lib/annotation_exporter.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
"use strict";
'use strict';
const path = require('path');
const glob = require('glob');
const fs = require('fs-extra');
const JSON5 = require('json5');
const _ = require('lodash');
const mp = require('./markdown_parser');

var path = require('path'),
glob = require('glob'),
fs = require('fs-extra'),
JSON5 = require('json5'),
_ = require('lodash'),
mp = require('./markdown_parser');
const annotations_exporter = function (pl) {

var annotations_exporter = function (pl) {

var paths = pl.config.paths;
const paths = pl.config.paths;
let oldAnnotations;

/*
Returns the array of comments that used to be wrapped in raw JS.
*/
function parseAnnotationsJS() {
//attempt to read the file
try {
var oldAnnotations = fs.readFileSync(path.resolve(paths.source.annotations, 'annotations.js'), 'utf8');
oldAnnotations = fs.readFileSync(path.resolve(paths.source.annotations, 'annotations.js'), 'utf8');
} catch (ex) {
if (pl.config.debug) {
console.log('annotations.js file missing from ' + paths.source.annotations + '. This may be expected.');
Expand All @@ -40,8 +40,8 @@ var annotations_exporter = function (pl) {
}

function buildAnnotationMD(annotationsYAML, markdown_parser) {
var annotation = {};
var markdownObj = markdown_parser.parse(annotationsYAML);
const annotation = {};
const markdownObj = markdown_parser.parse(annotationsYAML);

annotation.el = markdownObj.el || markdownObj.selector;
annotation.title = markdownObj.title;
Expand All @@ -50,16 +50,16 @@ var annotations_exporter = function (pl) {
}

function parseMDFile(annotations, parser) {
var annotations = annotations;
var markdown_parser = parser;
//let annotations = annotations;
const markdown_parser = parser;

return function (filePath) {
var annotationsMD = fs.readFileSync(path.resolve(filePath), 'utf8');
const annotationsMD = fs.readFileSync(path.resolve(filePath), 'utf8');

//take the annotation snippets and split them on our custom delimiter
var annotationsYAML = annotationsMD.split('~*~');
for (var i = 0; i < annotationsYAML.length; i++) {
var annotation = buildAnnotationMD(annotationsYAML[i], markdown_parser);
const annotationsYAML = annotationsMD.split('~*~');
for (let i = 0; i < annotationsYAML.length; i++) {
const annotation = buildAnnotationMD(annotationsYAML[i], markdown_parser);
annotations.push(annotation);
}
return false;
Expand All @@ -70,17 +70,17 @@ var annotations_exporter = function (pl) {
Converts the *.md file yaml list into an array of annotations
*/
function parseAnnotationsMD() {
var markdown_parser = new mp();
var annotations = [];
var mdFiles = glob.sync(paths.source.annotations + '/*.md');
const markdown_parser = new mp();
const annotations = [];
const mdFiles = glob.sync(paths.source.annotations + '/*.md');

mdFiles.forEach(parseMDFile(annotations, markdown_parser));
return annotations;
}

function gatherAnnotations() {
var annotationsJS = parseAnnotationsJS();
var annotationsMD = parseAnnotationsMD();
const annotationsJS = parseAnnotationsJS();
const annotationsMD = parseAnnotationsMD();
return _.unionBy(annotationsJS, annotationsMD, 'el');
}

Expand Down
18 changes: 9 additions & 9 deletions core/lib/changes_hunter.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"use strict";
const fs = require("fs-extra"),
CompileState = require('./object_factory').CompileState;
'use strict';
const fs = require("fs-extra");
const CompileState = require('./object_factory').CompileState;

/**
* For detecting changed patterns.
* @constructor
*/
let ChangesHunter = function () {
const ChangesHunter = function () {
};

ChangesHunter.prototype = {
Expand All @@ -24,11 +24,11 @@ ChangesHunter.prototype = {
checkBuildState: function (pattern, patternlab) {

//write the compiled template to the public patterns directory
let renderedTemplatePath =
const renderedTemplatePath =
patternlab.config.paths.public.patterns + pattern.getPatternLink(patternlab, 'rendered');

//write the compiled template to the public patterns directory
let markupOnlyPath =
const markupOnlyPath =
patternlab.config.paths.public.patterns + pattern.getPatternLink(patternlab, 'markupOnly');

if (!pattern.compileState) {
Expand All @@ -45,7 +45,7 @@ ChangesHunter.prototype = {
// Prevent error message if file does not exist
fs.accessSync(renderedFile, fs.F_OK)
);
let outputLastModified = fs.statSync(renderedTemplatePath).mtime.getTime();
const outputLastModified = fs.statSync(renderedTemplatePath).mtime.getTime();

if (pattern.lastModified && outputLastModified > pattern.lastModified) {
pattern.compileState = CompileState.CLEAN;
Expand All @@ -55,7 +55,7 @@ ChangesHunter.prototype = {
pattern.compileState = CompileState.NEEDS_REBUILD;
}

let node = patternlab.graph.node(pattern);
const node = patternlab.graph.node(pattern);

// Make the pattern known to the PatternGraph and remember its compileState
if (!node) {
Expand All @@ -78,7 +78,7 @@ ChangesHunter.prototype = {
checkLastModified: function (currentPattern, file) {
if (file) {
try {
let stat = fs.statSync(file);
const stat = fs.statSync(file);

// Needs recompile whenever one of the patterns files (template, json, pseudopatterns) changed
currentPattern.lastModified =
Expand Down
45 changes: 22 additions & 23 deletions core/lib/lineage_hunter.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
"use strict";
'use strict';
const extend = require("util")._extend;

var extend = require("util")._extend;
const lineage_hunter = function () {

var lineage_hunter = function () {

var pa = require('./pattern_assembler');
const pa = require('./pattern_assembler');

function findlineage(pattern, patternlab) {
// As we are adding edges from pattern to ancestor patterns, ensure it is known to the graph
patternlab.graph.add(pattern);

var pattern_assembler = new pa();
const pattern_assembler = new pa();

//find the {{> template-name }} within patterns
var matches = pattern.findPartials();
const matches = pattern.findPartials();
if (matches !== null) {
matches.forEach(function (match) {
//get the ancestorPattern
var ancestorPattern = pattern_assembler.getPartial(pattern.findPartial(match), patternlab);
const ancestorPattern = pattern_assembler.getPartial(pattern.findPartial(match), patternlab);

if (ancestorPattern && pattern.lineageIndex.indexOf(ancestorPattern.patternPartial) === -1) {
//add it since it didnt exist
pattern.lineageIndex.push(ancestorPattern.patternPartial);

//create the more complex patternLineage object too
var l = {
const l = {
"lineagePattern": ancestorPattern.patternPartial,
"lineagePath": "../../patterns/" + ancestorPattern.patternLink
};
Expand All @@ -44,7 +43,7 @@ var lineage_hunter = function () {
ancestorPattern.lineageRIndex.push(pattern.patternPartial);

//create the more complex patternLineage object in reverse
var lr = {
const lr = {
"lineagePattern": pattern.patternPartial,
"lineagePath": "../../patterns/" + pattern.patternLink
};
Expand All @@ -69,15 +68,15 @@ var lineage_hunter = function () {
* @param graph {PatternGraph}
*/
function setPatternState(direction, pattern, targetPattern, graph) {
var index = null;
let index = null;
if (direction === 'fromPast') {
index = graph.lineage(pattern);
} else {
index = graph.lineageR(pattern);
}

// if the request came from the past, apply target pattern state to current pattern lineage
for (var i = 0; i < index.length; i++) {
for (let i = 0; i < index.length; i++) {
if (index[i].patternPartial === targetPattern.patternPartial) {
index[i].lineageState = targetPattern.patternState;
}
Expand All @@ -87,36 +86,36 @@ var lineage_hunter = function () {

function cascadePatternStates(patternlab) {

for (var i = 0; i < patternlab.patterns.length; i++) {
var pattern = patternlab.patterns[i];
for (let i = 0; i < patternlab.patterns.length; i++) {
const pattern = patternlab.patterns[i];

//for each pattern with a defined state
if (pattern.patternState) {
var lineage = patternlab.graph.lineage(pattern);
const lineage = patternlab.graph.lineage(pattern);

if (lineage && lineage.length > 0) {

//find all lineage - patterns being consumed by this one
for (var h = 0; h < lineage.length; h++) {
for (let h = 0; h < lineage.length; h++) {
// Not needed, the graph already knows the concrete pattern
// var lineagePattern = pattern_assembler.getPartial(lineageIndex[h], patternlab);
// let lineagePattern = pattern_assembler.getPartial(lineageIndex[h], patternlab);
setPatternState('fromFuture', lineage[h], pattern, patternlab.graph);
}
}
var lineageR = patternlab.graph.lineageR(pattern);
const lineageR = patternlab.graph.lineageR(pattern);
if (lineageR && lineageR.length > 0) {

//find all reverse lineage - that is, patterns consuming this one
for (var j = 0; j < lineageR.length; j++) {
for (let j = 0; j < lineageR.length; j++) {

var lineageRPattern = lineageR[j];
const lineageRPattern = lineageR[j];

//only set patternState if pattern.patternState "is less than" the lineageRPattern.patternstate
//or if lineageRPattern.patternstate (the consuming pattern) does not have a state
//this makes patternlab apply the lowest common ancestor denominator
let patternStateCascade = patternlab.config.patternStateCascade;
let patternStateIndex = patternStateCascade.indexOf(pattern.patternState);
let patternReverseStateIndex = patternStateCascade.indexOf(lineageRPattern.patternState);
const patternStateCascade = patternlab.config.patternStateCascade;
const patternStateIndex = patternStateCascade.indexOf(pattern.patternState);
const patternReverseStateIndex = patternStateCascade.indexOf(lineageRPattern.patternState);
if (lineageRPattern.patternState === '' || (patternStateIndex < patternReverseStateIndex)) {

if (patternlab.config.debug) {
Expand Down
Loading