Skip to content

Commit

Permalink
Merge pull request #6 from gingeranyhow/master
Browse files Browse the repository at this point in the history
Add additional valid parameters to linting rules
  • Loading branch information
awmcclain authored Feb 16, 2019
2 parents 4abfbac + daa5c9d commit f8b65ca
Showing 1 changed file with 117 additions and 28 deletions.
145 changes: 117 additions & 28 deletions app/linter/ink-linter.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
var glob = require('glob'),
fs = require('fs'),
colors = require('colors/safe');

var defaultDir = '../Assets/Ink Files/';

// Run just against GDC rides
var filesToLint = defaultDir + 'GDCDemo/Rides/*.ink';


var sendOutputToStream = false;
var collectedOutput;
// OR, run against all Rides
// var filesToLint = defaultDir + '{,GDCDemo/}' + "Rides/{**,!(NotInUse)/}*.ink"

/* RUN LINTING TESTS */
/* Run the command `ava linter-test.js` within the test directory
/* TODO:
Implement:
/* TODO:
Implement:
1. react tag with an emote arg, and vice versa - invalid: >>react:happy >>emote:squint
2. discuss the new, skipped test with Andrew. Is it worth trying to handle ink tags with colons, or are we just
reimplementing the Inky tag-parser.
reimplementing the Inky tag-parser.
3. (Defer) Character tags with mis-spelled characters
/* REGEX PATTERNS */
Expand All @@ -37,11 +36,78 @@ const checkForInlineLogic = /^[+*\s-]*\{[A-Z()]{3,}:(.*?)\}/iu
/* LINTING REQUIREMENTS PER TAG CATEGORY*/

let charTagsParam = {
tags: ['react', 'emote', 'skin', 'hud', 'intensity'],
tags: ['react', 'emote', 'skin', 'hud', 'intensity', 'pose', 'anim'],
linter: hasCharacterTagError,
needsParam: true,
validParams: {
intensity: ["high", "medium", 'med', "low", 'h', 'm', 'l']
intensity: ["high", "medium", 'med', "low", 'h', 'm', 'l'],
emote: [
'dynamic',
'disgust',
'anxious',
'neutral',
'sad',
'happy',
'angry',
'chill',
'overjoyed',
'tired',
'wired',
'flirty'
],
pose: [
'ignore',
'focus',
'off',
],
anim: [
'off',
'on',
'ticket',
'savywanted',
'focus',
'ignore',
'typing'],
react: [
'look_up',
'look_down',
'look_right',
'look_ahead',
'look_left',
// 'lookleft', // Not valid, use underscore versions above.
// 'lookright', // Not valid, use underscore versions above.
// 'lookDown', // Not valid, use underscore versions above.
// 'lookdown', // Not valid, use underscore versions above.
'laugh',
// 'notice', // No longer valid, use look_up, look_down, etc.
// 'notice_destination', // No longer valid, use look_up, look_down, etc.
'frown',
'squint',
'look',
'shifty',
'smirk',
'surprise',
// 'surprised', // DO NOT ADD BACK. Use 'surprise' for this react.
'huh',
'wink',
'nod',
'awkward',
'yawn',
'laugh',
'shrug',
'nod',
'sigh',
'yes',
'smile',
'shake',
'frown_sad',
'eyeroll',
'eyes_widen',
'wow',
'huh',
'pretty_please',
'shock',
]
}
}

Expand All @@ -57,8 +123,29 @@ let storyTags = {
linter: hasStoryTagError,
needsParam: true,
validParams: {
cutCamera: ['linapov', 'paxleft', 'paxright', 'dashcam', 'hoodcam', 'linafront', 'city'],
linaHands: ['checkwatch']
cutCamera: [
'linapov',
'linapovclose',
'linaclose',
'linafront',
'linafrontclose',
'paxleft',
'paxright',
'dashcam',
'hoodcam',
'city',
'establishing',
'reverseclose',
'reversewide',
//'savyclose', // THIS IS INVALID, use savycloseup
'savycloseup',
'overshoulder',
],
linaHands: [
'checkwatch',
'lookcenter',
'lookleft'
]
}
}

Expand All @@ -71,12 +158,14 @@ let simpleTags = {
}

let tagsWithoutEvents = {
linter: hasUITagError,
linter: hasUITagError,
needsParam: true,
tags:
tags:
["id",
"stars",
"Title",
'Subheader',
'cost',
"DisplayName",
"Reviewers",
"Length",
Expand Down Expand Up @@ -112,8 +201,8 @@ let tagsWithoutEvents = {

let uiTags = {
linter: hasUITagError,
needsParam: true,
tags:
needsParam: true,
tags:
["UIView",
"UILabel",
"UIButton",
Expand Down Expand Up @@ -160,7 +249,7 @@ var errorType = "foo"; // Used for unit test to make sure the correct log is sho

function hasCharacterTagError(matchObject) {
let decoratedMatchObject = decorateCharTags(matchObject);

// run basic character tag linting
if (checkForInValidCharacterTagForm(decoratedMatchObject)) return true;

Expand All @@ -184,7 +273,7 @@ function checkForInValidCharacterTagForm(decoratedMatchObject) {
if (!decoratedMatchObject.character || !decoratedMatchObject.type) {
logBadTag(`Character tag missing or malformed: ${decoratedMatchObject.fullTag}`, decoratedMatchObject);
return true;
}
}

if(!decoratedMatchObject.type) {
logBadTag('Character type (inline or leadingName) could not be determined', decoratedMatchObject);
Expand All @@ -206,7 +295,7 @@ function isValidPauseTag(matchObject) {
}


// Function that identifies the character name and parameters
// Function that identifies the character name and parameters
// for both of the two distint character types (inline and leading)
function decorateCharTags(matchObject) {
// TYPE: inline
Expand All @@ -224,7 +313,7 @@ function decorateCharTags(matchObject) {
matchObject.character = matchObject.semiColonArg;
matchObject.parameter = matchObject.periodArg;
return matchObject;
}
}

let charMatch = matchObject.line.match(extractNameFromValidLine);

Expand All @@ -245,7 +334,7 @@ function hasStoryTagError(matchObject) {
// story tags must have an argument after the semiColon
if (!matchObject.semiColonArg) {
logBadTag(`Story tag '${matchObject.fullTag}' missing argument`, matchObject);
return true;
return true;
}

//some story tags have validation on their argument
Expand All @@ -255,12 +344,12 @@ function hasStoryTagError(matchObject) {
//story tags must have no argument after the period
//unless it's a valid decimal-containing pause story tag
if (matchObject.periodArg && !isValidPauseTag(matchObject)) {

logBadTag(`Story tag '${matchObject.fullTag}' malformed: ${matchObject.fullTag}`, matchObject);
return true;
}

return false;
return false;
}

function hasUITagError(matchObject) {
Expand All @@ -279,11 +368,11 @@ function hasTesterTagError(matchObject) {
// tester tags must have an argument
if (!matchObject.semiColonArg) {
logBadTag(`Story tag '${matchObject.fullTag}' missing argument`, matchObject);
return true;
return true;
}

if (hasInvalidParam(matchObject, matchObject.semiColonArg)) return true;
return false;
return false;
}

function hasInvalidParam(matchObject, param) {
Expand All @@ -300,7 +389,7 @@ function isCommented(line) {
return RegExp(checkForCommentedLine).test(line);
}

/* FILE THAT RUNS LINES AND FILES THROUGH LINTING*/
/* FILE THAT RUNS LINES AND FILES THROUGH LINTING*/

function logBadTag(message, matchObject) {
let errorDetails = `${message}\n` + colors.yellow(matchObject.line);
Expand All @@ -313,7 +402,7 @@ function logBadTag(message, matchObject) {

function lintInkFile(path) {
let text = fs.readFile(path, 'utf8', function(err, data) {
lintBuffer(data);
lintBuffer(path, data);
});
}

Expand Down Expand Up @@ -370,7 +459,7 @@ function hasLineErrors(line, lineNumber, path) {

} else {
// Check for case errors
let closeMatch = Object.keys(tagsAndLinting).find((key) => key.toLowerCase() == matchObject.tagName.toLowerCase());
let closeMatch = Object.keys(tagsAndLinting).find((key) => key.toLowerCase() == matchObject.tagName.toLowerCase());
let closeMatchPrompt = closeMatch ? `. Did you mean '>>${closeMatch}'?` : "";
logBadTag(`Unknown tag: '>>${matchObject.tagName}'${closeMatchPrompt}`, matchObject);
lineError = true;
Expand All @@ -385,8 +474,8 @@ glob(filesToLint, function( err, files ) {
if( err ) {
console.error( "Could not list the directory.", err );
process.exit( 1 );
}
}

files.forEach(lintInkFile);
console.log('File to review:', files.length);
});
Expand Down

0 comments on commit f8b65ca

Please sign in to comment.