diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..c07b8ed --- /dev/null +++ b/.clang-format @@ -0,0 +1,90 @@ +--- +Language: JavaScript +# BasedOnStyle: Google +AccessModifierOffset: -1 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlinesLeft: true +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: true +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: true +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: true +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +IncludeCategories: + - Regex: '^<.*\.h>' + Priority: 1 + - Regex: '^<.*' + Priority: 2 + - Regex: '.*' + Priority: 3 +IndentCaseLabels: true +IndentWidth: 2 +IndentWrappedFunctionNames: false +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: false +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 +PointerAlignment: Left +ReflowComments: true +SortIncludes: true +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Auto +TabWidth: 8 +UseTab: Never +... + diff --git a/pedant.js b/pedant.js index 1e37a29..74d92ca 100644 --- a/pedant.js +++ b/pedant.js @@ -1,52 +1,57 @@ -var text = "'The quick brown,fox jumped over the lazy dog, he said, as he noticed that he forgot to close the quote."; +var text = + "'The quick brown,fox jumped over the lazy dog, he said, as he noticed that he forgot to close the quote."; var MAX_QUOTE_LENGTH = 20; var ERROR_SEPERATOR = "\n"; -var punctuation = [',', '.', '!', ';', ';', '"']; -var quotes = ['"', "'"]; +var punctuation = [ ',', '.', '!', ';', ';', '"' ]; +var quotes = [ '"', "'" ]; for (var i = 0; i < text.length; i++) { - - // check for punctuation - if (punctuation.indexOf(text[i]) > -1) { - if ((text[i + 1] != " ") && (i != text.length - 1)) { - console.log("PunctuationError: no space after punctuation at index " + i + ":"); - var error = showPrettyError(text, i); - console.log(error[0]); - console.log(error[1]); - console.log(ERROR_SEPERATOR); - } + // check for punctuation + if (punctuation.indexOf(text[i]) > -1) { + if ((text[i + 1] != " ") && (i != text.length - 1)) { + console.log("PunctuationError: no space after punctuation at index " + i + + ":"); + var error = showPrettyError(text, i); + console.log(error[0]); + console.log(error[1]); + console.log(ERROR_SEPERATOR); } + } - // check for missing quotes - if (quotes.indexOf(text[i]) > -1) { - var k = 0; - for (j = 1; j < text.length; j++) { - if (quotes.indexOf(text[j]) == -1) { - k++; - } - } - - if (k > MAX_QUOTE_LENGTH) { - var error = showPrettyError(text, i); - console.log(error[0]); - console.log(error[1]); - console.log("QuoteError: max quote length of " + MAX_QUOTE_LENGTH + " exceeded at index " + j + " (quote started at index " + i + "):"); - console.log(ERROR_SEPERATOR); - } + // check for missing quotes + if (quotes.indexOf(text[i]) > -1) { + var k = 0; + for (j = 1; j < text.length; j++) { + if (quotes.indexOf(text[j]) == -1) { + k++; + } + } + if (k > MAX_QUOTE_LENGTH) { + var error = showPrettyError(text, i); + console.log(error[0]); + console.log(error[1]); + console.log("QuoteError: max quote length of " + MAX_QUOTE_LENGTH + + " exceeded at index " + j + " (quote started at index " + i + + "):"); + console.log(ERROR_SEPERATOR); } + } } function showPrettyError(text, index) { - var contextAmount = 8; - var showContextSegment = "..."; - return [ - showContextSegment + text.substr(index - contextAmount, index + contextAmount) + showContextSegment, - pad(Math.max(index + 1 - contextAmount, index + 1), "^", " ").substr(index - contextAmount - showContextSegment.length) - ]; - - //http://stackoverflow.com/a/15660515 - function pad(width, string, padding) { - return (width <= string.length) ? string : pad(width, padding + string, padding); - } + var contextAmount = 8; + var showContextSegment = "..."; + return [ + showContextSegment + + text.substr(index - contextAmount, index + contextAmount) + + showContextSegment, + pad(Math.max(index + 1 - contextAmount, index + 1), "^", " ") + .substr(index - contextAmount - showContextSegment.length) + ]; + // http://stackoverflow.com/a/15660515 + function pad(width, string, padding) { + return (width <= string.length) ? string + : pad(width, padding + string, padding); + } }