From 690f9e9aedb79bf9ace04aff97f1c51d7e93a378 Mon Sep 17 00:00:00 2001 From: Thibault Kruse Date: Tue, 23 Aug 2016 11:04:01 +0200 Subject: [PATCH 1/2] repair markdown checking --- scripts/Makefile | 18 +++++++++++------ scripts/nodejs/package.json | 34 +-------------------------------- scripts/nodejs/remark/.remarkrc | 31 ++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 39 deletions(-) create mode 100644 scripts/nodejs/remark/.remarkrc diff --git a/scripts/Makefile b/scripts/Makefile index a992333..b407bd7 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -37,16 +37,17 @@ distclean: #### check markdown -## run remark markdown checker based on configuration in package.json +## run remark markdown checker based on configuration in .remarkrc .PHONY: check-markdown -check-markdown: nodejs/node_modules/remark nodejs/package.json $(SOURCEPATH) $(BUILD_DIR) Makefile +check-markdown: nodejs/node_modules/remark nodejs/remark/.remarkrc $(SOURCEPATH) $(BUILD_DIR) Makefile + echo '##################### Markdown check ##################' ## run remark, paste output to temporary file - cd nodejs; ./node_modules/.bin/remark ../$(SOURCEPATH) --no-color -q 1> ../$(BUILD_DIR)/$(SOURCEFILE).fixed --frail + cd nodejs; ./node_modules/.bin/remark ../$(SOURCEPATH) --no-color -q --config-path ./remark/.remarkrc 1> ../$(BUILD_DIR)/$(SOURCEFILE).fixed --frail ## show a diff with changes remark suggests .PHONY: show-diff -show-diff: nodejs/node_modules/remark nodejs/package.json $(SOURCEPATH) $(BUILD_DIR) Makefile - cd nodejs; ./node_modules/.bin/remark ../$(SOURCEPATH) --no-color -q 1> ../$(BUILD_DIR)/$(SOURCEFILE).fixed +show-diff: nodejs/node_modules/remark nodejs/remark/.remarkrc $(SOURCEPATH) $(BUILD_DIR) Makefile + cd nodejs; ./node_modules/.bin/remark ../$(SOURCEPATH) --no-color -q --config-path ./remark/.remarkrc 1> ../$(BUILD_DIR)/$(SOURCEFILE).fixed ## compare temporary file to original, error and fail with message if differences exist diff $(SOURCEPATH) $(BUILD_DIR)/$(SOURCEFILE).fixed -u3 || \ (echo "Error: remark found bad markdown syntax, see output above" && false) @@ -54,6 +55,7 @@ show-diff: nodejs/node_modules/remark nodejs/package.json $(SOURCEPATH) $(BUILD_ .PHONY: check-references check-references: $(SOURCEPATH) $(BUILD_DIR) Makefile + @echo '##################### References check ##################' ## check references unique @rm -f $(BUILD_DIR)/$(SOURCEFILE).uniq @grep -oP '(?<= $(BUILD_DIR)/$(SOURCEFILE).uniq @@ -62,6 +64,7 @@ check-references: $(SOURCEPATH) $(BUILD_DIR) Makefile .PHONY: check-notabs check-notabs: $(SOURCEPATH) $(BUILD_DIR) Makefile + @echo '##################### Tabs check ##################' # find lines with tabs # old file still might be around @rm -f $(BUILD_DIR)/CppCoreGuidelines.md.tabs @@ -71,6 +74,7 @@ check-notabs: $(SOURCEPATH) $(BUILD_DIR) Makefile .PHONY: check-badchars check-badchars: $(SOURCEPATH) $(BUILD_DIR) Makefile + @echo '##################### Bad chars check ##################' # find lines with tabs # old file still might be around @rm -f $(BUILD_DIR)/CppCoreGuidelines.md.badchars @@ -81,8 +85,9 @@ check-badchars: $(SOURCEPATH) $(BUILD_DIR) Makefile .PHONY: hunspell-check hunspell-check: $(BUILD_DIR)/plain-nohtml.txt + @echo '##################### Spell check ##################' hunspell -p hunspell/isocpp.dic -u < build/plain-nohtml.txt > $(BUILD_DIR)/hunspell-report.txt - if [ -s $(BUILD_DIR)/hunspell-report.txt ]; then echo 'Warning: Spellcheck failed, fix words or add to dictionary:'; cat $(BUILD_DIR)/hunspell-report.txt; false; fi; + @if [ -s $(BUILD_DIR)/hunspell-report.txt ]; then echo 'Warning: Spellcheck failed, fix words or add to dictionary:'; cat $(BUILD_DIR)/hunspell-report.txt; false; fi; # only list words that are not in dict # to include all add them to bottom of hunspell/isocpp.dict, and run @@ -95,6 +100,7 @@ hunspell-list: $(BUILD_DIR)/plain.txt .PHONY: cpplint-all cpplint-all: $(BUILD_DIR)/codeblocks $(BUILD_DIR)/Makefile python/Makefile.in + @echo '##################### C++ Style check ##################' cd $(BUILD_DIR)/codeblocks; $(MAKE) cpplint-all -k #### generic makefile for sourceblocks (need to be evaluated after c++ file generation) diff --git a/scripts/nodejs/package.json b/scripts/nodejs/package.json index 0f94c26..ff4453a 100644 --- a/scripts/nodejs/package.json +++ b/scripts/nodejs/package.json @@ -7,38 +7,6 @@ "remark": "^4.2.2", "remark-lint": "^4.0.2", "remark-lint-sentence-newline": "^2.0.0", - "remark-validate-links": "^4.1.0", - "remark-lint-are-links-valid": "^1.0.2" - }, - "remarkConfig": { - "plugins": { - "remark-lint": { - "unordered-list-marker-style": "consistent", - "list-item-bullet-indent": false, - "list-item-indent": false, - "list-item-spacing": false, - "no-html": false, - "maximum-line-length": false, - "no-file-name-mixed-case": false, - "heading-increment": false, - "no-multiple-toplevel-headings": false, - "no-consecutive-blank-lines": false, - "maximum-line-length": 9000, - "maximum-heading-length": 300, - "no-heading-punctuation": false, - "no-duplicate-headings": false, - "emphasis-marker": "*", - "no-tabs": false, - "blockquote-indentation": false, - "strong-marker": "*", - "external": ["remark-lint-are-links-valid"] - } - }, - "settings": { - "bullet": "*", - "listItemIndent": "1", - "strong": "*", - "emphasis": "*" - } + "remark-validate-links": "^4.1.0" } } diff --git a/scripts/nodejs/remark/.remarkrc b/scripts/nodejs/remark/.remarkrc new file mode 100644 index 0000000..9b4ed37 --- /dev/null +++ b/scripts/nodejs/remark/.remarkrc @@ -0,0 +1,31 @@ +{ + "presets": ["lint-recommended", "lint-consistent"], + "plugins": { + "remark-lint": { + "unordered-list-marker-style": "consistent", + "list-item-bullet-indent": true, + "list-item-indent": false, + "list-item-spacing": false, + "no-html": false, + "maximum-line-length": false, + "no-file-name-mixed-case": false, + "heading-increment": false, + "no-multiple-toplevel-headings": true, + "no-consecutive-blank-lines": false, + "maximum-line-length": 9000, + "maximum-heading-length": 300, + "no-heading-punctuation": false, + "no-duplicate-headings": false, + "emphasis-marker": "*", + "no-tabs": true, + "blockquote-indentation": false, + "strong-marker": "*" + } + }, + "settings": { + "bullet": "*", + "listItemIndent": "1", + "strong": "*", + "emphasis": "*" + } +} From d9185256096ede3864374a3a69c9ccdcdb360ec2 Mon Sep 17 00:00:00 2001 From: Thibault Kruse Date: Fri, 26 Aug 2016 04:51:41 +0200 Subject: [PATCH 2/2] python: fix superfluous newline in extracted plain.txt, causes bad line numbers in spell check --- scripts/python/md-split.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/python/md-split.py b/scripts/python/md-split.py index fb147e9..2e8e063 100755 --- a/scripts/python/md-split.py +++ b/scripts/python/md-split.py @@ -72,6 +72,8 @@ def main(): sline = stripped(line) text_filehandle.write(sline) + assert line_length(args.sourcefile) == line_length(args.targetfile) + def process_code(read_filehandle, text_filehandle, line, linenum, sourcefile, codedir, name, index, indent_depth): fenced = (line.strip() == '```') @@ -91,16 +93,17 @@ def process_code(read_filehandle, text_filehandle, line, linenum, sourcefile, co comment_idx = line.find('//') no_comment_line = line if comment_idx >= 0: - no_comment_line = line[:comment_idx] + no_comment_line = line[:comment_idx].strip() text_filehandle.write(line[comment_idx + 2:]) + else: + # write empty line so line numbers stay stable + text_filehandle.write('\n') + if (not has_actual_code and not line.strip().startswith('//') and not line.strip().startswith('???') and not line.strip() == ''): has_actual_code = True - else: - # write empty line so line numbers stay stable - text_filehandle.write('\n') if (not line.strip() == '```'): if ('???' == no_comment_line or '...' == no_comment_line): @@ -171,5 +174,8 @@ def get_marker(line): return None +def line_length(filename): + return sum(1 for line in open(filename)) + if __name__ == '__main__': main()