├── .github └── workflows │ ├── build.yml │ └── jekyll-gh-pages.yml ├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── CppCoreGuidelines.md ├── LICENSE ├── README.md ├── SECURITY.md ├── _config.yml ├── _includes ├── head.html └── sidebar.html ├── _layouts └── default.html ├── cpp_core_guidelines_16b.png ├── cpp_core_guidelines_logo_text.png ├── docs ├── Introduction to type and resource safety.pdf ├── Lifetime.pdf ├── P0122R4.pdf ├── ctor-dtor-raii-popl12.pdf └── gsl-intro.md ├── index.html ├── param-passing-advanced.png ├── param-passing-normal.png ├── params.json ├── public ├── css │ ├── custom.css │ ├── hyde.css │ └── poole.css └── images │ ├── bg_hr.png │ ├── blacktocat.png │ ├── icon_download.png │ └── sprite_download.png ├── scripts ├── Makefile ├── hunspell │ ├── en_US.aff │ ├── en_US.dic │ └── isocpp.dic ├── nodejs │ ├── package.json │ └── remark │ │ └── .remarkrc └── python │ ├── Makefile.in │ ├── cpplint.py │ ├── cpplint_wrap.py │ └── md-split.py └── talks ├── Contracts-for-Dependable-C++.pdf ├── Large-Scale-C++-With-Modules.pdf ├── MacIntosh - A Few Good Types.pdf ├── MacIntosh - Static Analysis and C++.pdf ├── README.md ├── Stroustrup - CppCon 2015 keynote.pdf └── Sutter - CppCon 2015 day 2 plenary .pdf /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | on: [push, pull_request] 3 | 4 | jobs: 5 | build: 6 | runs-on: ubuntu-latest 7 | 8 | steps: 9 | - uses: actions/checkout@master 10 | 11 | - name: Install Hunspell 12 | run: | 13 | sudo apt-get update 14 | sudo apt-get install hunspell 15 | 16 | - name: Run cd scripts; make -k 17 | run: cd scripts; make -k 18 | 19 | - name: Run cd .. 20 | run: cd .. 21 | -------------------------------------------------------------------------------- /.github/workflows/jekyll-gh-pages.yml: -------------------------------------------------------------------------------- 1 | # Sample workflow for building and deploying a Jekyll site to GitHub Pages 2 | name: Deploy Jekyll with GitHub Pages dependencies preinstalled 3 | 4 | on: 5 | # Runs on pushes targeting the default branch 6 | push: 7 | branches: ["master"] 8 | 9 | # Allows you to run this workflow manually from the Actions tab 10 | workflow_dispatch: 11 | 12 | # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages 13 | permissions: 14 | contents: read 15 | pages: write 16 | id-token: write 17 | 18 | # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. 19 | # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. 20 | concurrency: 21 | group: "pages" 22 | cancel-in-progress: false 23 | 24 | jobs: 25 | # Build job 26 | build: 27 | runs-on: ubuntu-latest 28 | steps: 29 | - name: Checkout 30 | uses: actions/checkout@v4 31 | - name: Setup Pages 32 | uses: actions/configure-pages@v5 33 | - name: Build with Jekyll 34 | uses: actions/jekyll-build-pages@v1 35 | with: 36 | source: ./ 37 | destination: ./_site 38 | - name: Upload artifact 39 | uses: actions/upload-pages-artifact@v3 40 | 41 | # Deployment job 42 | deploy: 43 | environment: 44 | name: github-pages 45 | url: ${{ steps.deployment.outputs.page_url }} 46 | runs-on: ubuntu-latest 47 | needs: build 48 | steps: 49 | - name: Deploy to GitHub Pages 50 | id: deployment 51 | uses: actions/deploy-pages@v4 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | scripts/build 2 | scripts/nodesjs/build 3 | node_modules 4 | _site 5 | scripts/python/__pycache__ 6 | scripts/python/*.pyc 7 | 8 | # VS Code 9 | .vs/ 10 | 11 | # MacOS-specific 12 | .DS_Store -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # This is the configuration for Travis CI, a free github-integrated service that runs this script for each pull request (if configured) 2 | 3 | # provides gcc, clang, make, scons, cmake 4 | language: c++ 5 | 6 | # alternatives: gcc, clang, or both (as yaml list) 7 | compiler: clang 8 | 9 | addons: 10 | apt: 11 | packages: 12 | - hunspell 13 | 14 | install: 15 | - 16 | 17 | script: 18 | - cd scripts; make -k 19 | - cd .. 20 | 21 | notifications: 22 | email: false 23 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing to the C++ Core Guidelines 2 | 3 | >"Within C++ is a smaller, simpler, safer language struggling to get out." 4 | >-- Bjarne Stroustrup 5 | 6 | The C++ Core Guidelines are a collaborative effort led by Bjarne Stroustrup, much like the C++ language itself. They are the result of many 7 | person-years of discussion and design across a number of organizations. Their design encourages general applicability and broad adoption but 8 | they can be freely copied and modified to meet your organization's needs. 9 | 10 | We encourage contributions to the C++ Core Guidelines in a number of ways: 11 | - **Individual feedback** Are you a developer who is passionate about your code? Join the discussion in 12 | [Issues](https://github.com/isocpp/CppCoreGuidelines/issues). We want to know which rules resonate with you and which don't. Were any rules 13 | inordinately difficult to apply? Does your compiler vendor's Guidelines Support Library (e.g., 14 | [Microsoft's implementation of the GSL](https://github.com/microsoft/gsl)) suit your needs in adopting these guidelines? 15 | - **Organizational adoption** While the guidelines are designed to be broadly adoptable they are also intended to be modified to fit your 16 | organization's particular needs. We encourage your organization to fork this repo and create your own copy of these guidelines with changes 17 | that reflect your needs. We suggest that you make it clear in the title of your guidelines that these are your organization's fork of the 18 | guidelines and that you provide a link back to the original set of [guidelines](https://github.com/isocpp/CppCoreGuidelines). And if any of 19 | your local changes are appropriate to pull back into the original guidelines, please open an 20 | [Issue](https://github.com/isocpp/CppCoreGuidelines/issues) which can lead to a pull request. 21 | - **Maintain the Guidelines** The C++ Core Guidelines were created from a wealth of knowledge spread across a number of organizations 22 | worldwide. If you or your organization is passionate about helping to create the guidelines, consider becoming an editor or maintainer. If 23 | you're a C++ expert who is serious about participating, please 24 | [email coreguidelines@isocpp.org](mailto:coreguidelines@isocpp.org?subject=Maintain%20the%20C++%20Code%20Guidelines). 25 | 26 | ## Contributor License Agreement 27 | By contributing content to the C++ Core Guidelines (i.e., submitting a pull request for inclusion in this repository) you agree with the 28 | [Standard C++ Foundation](https://isocpp.org/about) [Terms of Use](https://isocpp.org/home/terms-of-use), especially all of the terms specified 29 | regarding Copyright and Patents. 30 | - You warrant that your material is original, or you have the right to contribute it. 31 | - With respect to the material that you own, you grant a worldwide, non-exclusive, irrevocable, transferable, and royalty-free license to your contributed 32 | material to Standard C++ Foundation to display, reproduce, perform, distribute, and create derivative works of that material for commercial or 33 | non-commercial use. With respect to any other material you contribute, such material must be under a license sufficient to allow Standard C++ Foundation 34 | to display, reproduce, perform, distribute, and create derivative works of that material for commercial or non-commercial use. 35 | - You agree that, if your contributed material is subsequently reflected in the ISO/IEC C++ standard in any form, it will be subject to all ISO/IEC JTC 36 | 1 policies including [copyrights](http://www.iso.org/iso/home/policies.htm), 37 | [patents](http://www.iso.org/iso/home/standards_development/governance_of_technical_work/patents.htm), and 38 | [procedures](http://www.itscj.ipsj.or.jp/sc29/29w7proc.htm); please direct any questions about these policies to the 39 | [ISO Central Secretariat](http://www.iso.org/iso/home/about.htm). 40 | 41 | 42 | ## Pull requests 43 | 44 | We welcome pull requests for scoped changes to the guidelines--bug fixes in 45 | examples, clarifying ambiguous text, etc. Significant changes should first be 46 | discussed in the [Issues](https://github.com/isocpp/CppCoreGuidelines/issues) 47 | and the Issue number must be included in the pull request. For 48 | guideline-related changes, please specify the rule number in your Issue and/or 49 | Pull Request. 50 | 51 | Changes should be made in a child commit of a recent commit in the master 52 | branch. If you are making many small changes, please create separate PRs to 53 | minimize merge issues. 54 | 55 | ### Document Style Guidelines 56 | 57 | Documents in this repository are written in an unspecific flavor of Markdown, 58 | which leaves some ambiguity for formatting text. We ask that pull requests 59 | maintain the following style guidelines, though we are aware that the document 60 | may not already be consistent. 61 | 62 | #### Indentation 63 | 64 | Code and nested text should use multiples of 4 spaces of indentation, and no 65 | tab characters, like so: 66 | 67 | void func(const int x) 68 | { 69 | std::cout << x << '\n'; 70 | } 71 | 72 | #### Code Blocks 73 | 74 | Please use 4-space indentation to trigger code parsing, rather than [fenced code blocks](https://help.github.com/articles/github-flavored-markdown/#fenced-code-blocks) or any other style, like so: 75 | 76 | This is some document text, with an example below: 77 | 78 | void func() 79 | { 80 | std::cout << "This is code.\n"; 81 | } 82 | 83 | #### Document style decisions 84 | 85 | We've discussed and made decisions on a number of document style. Please do not open PRs that revisit these stylistic points: 86 | 87 | - The CppCoreGuidelines.md file is a single GH-flavored Markdown file. It is not split into separate chapters. 88 | - We do not use syntax highlighting in the Core Guidelines. See PRs #33, #96, #328, and #779. If you want syntax highlighting you 89 | can either view the "pretty" version at http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines or do your own post-processing. 90 | - We're sticking with the ASCII character set. We do not use Unicode em-dashes, Unicode spaces, or pretty quotes. Lots of people edit this file with their various text editors. ASCII is simple and universally understood. 91 | 92 | ### Update dictionary 93 | 94 | Code samples in the guidelines are run through a spelling checker. Be sure to add new class and variable names to [scripts/hunspell/isocpp.dic](https://github.com/isocpp/CppCoreGuidelines/blob/master/scripts/hunspell/isocpp.dic). 95 | 96 | ### Miscellaneous 97 | 98 | To avoid line-ending issues, please set `autocrlf = input` and `whitespace = cr-at-eol` in your git configuration. 99 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) Standard C++ Foundation and its contributors 2 | 3 | Standard C++ Foundation grants you a worldwide, nonexclusive, royalty-free, 4 | perpetual license to copy, use, modify, and create derivative works from this 5 | project for your personal or internal business use only. The above copyright 6 | notice and this permission notice shall be included in all copies or 7 | substantial portions of the project. This license does not grant permission 8 | to use the trade names, trademarks, service marks, or product names of the 9 | licensor, except as required for reasonable and customary use in describing 10 | the origin of the project. 11 | 12 | Standard C++ Foundation reserves the right to accept contributions to the 13 | project at its discretion. 14 | 15 | By contributing material to this project, you grant Standard C++ Foundation, 16 | and those who receive the material directly or indirectly from Standard C++ 17 | Foundation, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable, 18 | transferrable license to reproduce, prepare derivative works of, publicly 19 | display, publicly perform, and distribute your contributed material and such 20 | derivative works, and to sublicense any or all of the foregoing rights to third 21 | parties for commercial or non-commercial use. You also grant Standard C++ 22 | Foundation, and those who receive the material directly or indirectly from 23 | Standard C++ Foundation, a perpetual, worldwide, non-exclusive, royalty-free, 24 | irrevocable license under your patent claims that directly read on your 25 | contributed material to make, have made, use, offer to sell, sell and import 26 | or otherwise dispose of the material. You warrant that your material is your 27 | original work, or that you have the right to grant the above licenses. 28 | 29 | THE PROJECT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 31 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 32 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 33 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 34 | OUT OF OR IN CONNECTION WITH THE PROJECT OR THE USE OR OTHER DEALINGS IN THE 35 | PROJECT. 36 | 37 | If you believe that anything in the project infringes your copyright, please 38 | contact us at admin@isocpp.org with your contact information and a detailed 39 | description of your intellectual property, including a specific URL where you 40 | believe your intellectual property is being infringed. 41 | 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [](http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines) 2 | 3 | >"Within C++ is a smaller, simpler, safer language struggling to get out." 4 | >-- Bjarne Stroustrup 5 | 6 | The [C++ Core Guidelines](CppCoreGuidelines.md) are a collaborative effort led by Bjarne Stroustrup, much like the C++ language itself. They are the result of many 7 | person-years of discussion and design across a number of organizations. Their design encourages general applicability and broad adoption but 8 | they can be freely copied and modified to meet your organization's needs. 9 | 10 | ## Getting started 11 | 12 | The guidelines themselves are found at [CppCoreGuidelines](CppCoreGuidelines.md). The document is in [GH-flavored MarkDown](https://github.github.com/gfm/). It is intentionally kept simple, mostly in ASCII, to allow automatic post-processing such as language translation and reformatting. The editors maintain one 13 | [version formatted for browsing](http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines). Note that it is manually integrated and can be slightly older than the version in the master branch. 14 | 15 | The Guidelines are a constantly evolving document without a strict "release" cadence. Bjarne Stroustrup periodically reviews the document and increments the version number in the introduction. [Checkins that increment the version number](https://github.com/isocpp/CppCoreGuidelines/releases) are tagged in git. 16 | 17 | Many of the guidelines make use of the header-only Guidelines Support Library. One implementation is available at [GSL: Guidelines Support Library](https://github.com/Microsoft/GSL). 18 | 19 | ## Background and scope 20 | 21 | The aim of the guidelines is to help people to use modern C++ effectively. By "modern C++" we mean C++11 and newer. In other 22 | words, what would you like your code to look like in 5 years' time, given that you can start now? In 10 years' time? 23 | 24 | The guidelines are focused on relatively higher-level issues, such as interfaces, resource management, memory management, and concurrency. Such 25 | rules affect application architecture and library design. Following the rules will lead to code that is statically type-safe, has no resource 26 | leaks, and catches many more programming logic errors than is common in code today. And it will run fast -- you can afford to do things right. 27 | 28 | We are less concerned with low-level issues, such as naming conventions and indentation style. However, no topic that can help a programmer is 29 | out of bounds. 30 | 31 | Our initial set of rules emphasizes safety (of various forms) and simplicity. They may very well be too strict. We expect to have to introduce 32 | more exceptions to better accommodate real-world needs. We also need more rules. 33 | 34 | You will find some of the rules contrary to your expectations or even contrary to your experience. If we haven't suggested that you change your 35 | coding style in any way, we have failed! Please try to verify or disprove rules! In particular, we'd really like to have some of our rules 36 | backed up with measurements or better examples. 37 | 38 | You will find some of the rules obvious or even trivial. Please remember that one purpose of a guideline is to help someone who is less 39 | experienced or coming from a different background or language to get up to speed. 40 | 41 | The rules are designed to be supported by an analysis tool. Violations of rules will be flagged with references (or links) to the relevant rule. 42 | We do not expect you to memorize all the rules before trying to write code. 43 | 44 | The rules are meant for gradual introduction into a code base. We plan to build tools for that and hope others will too. 45 | 46 | ## Contributions and LICENSE 47 | 48 | Comments and suggestions for improvements are most welcome. We plan to modify and extend this document as our understanding improves and the 49 | language and the set of available libraries improve. More details are found at [CONTRIBUTING](./CONTRIBUTING.md) and [LICENSE](./LICENSE). 50 | 51 | Thanks to [DigitalOcean](https://www.digitalocean.com/?refcode=32f291566cf7&utm_campaign=Referral_Invite&utm_medium=Referral_Program&utm_source=CopyPaste) for hosting the Standard C++ Foundation website. 52 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Reporting a Vulnerability 4 | 5 | Please report vulnerabilities, if any, to cppcg-editors@isocpp.org 6 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | include: [CppCoreGuidelines.md] 2 | exclude: [docs, talks, Gemfile, params.json] 3 | -------------------------------------------------------------------------------- /_includes/head.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |`,
280 | * or to a parent if there are multiple elements to show.
281 | */
282 |
283 | .message {
284 | margin-bottom: 1rem;
285 | padding: 1rem;
286 | color: #717171;
287 | background-color: #f9f9f9;
288 | }
289 |
290 |
291 | /*
292 | * Container
293 | *
294 | * Center the page content.
295 | */
296 |
297 | .container {
298 | max-width: 38rem;
299 | padding-left: 1rem;
300 | padding-right: 1rem;
301 | margin-left: auto;
302 | margin-right: auto;
303 | }
304 |
305 |
306 | /*
307 | * Masthead
308 | *
309 | * Super small header above the content for site name and short description.
310 | */
311 |
312 | .masthead {
313 | padding-top: 1rem;
314 | padding-bottom: 1rem;
315 | margin-bottom: 3rem;
316 | }
317 | .masthead-title {
318 | margin-top: 0;
319 | margin-bottom: 0;
320 | color: #505050;
321 | }
322 | .masthead-title a {
323 | color: #505050;
324 | }
325 | .masthead-title small {
326 | font-size: 75%;
327 | font-weight: 400;
328 | color: #c0c0c0;
329 | letter-spacing: 0;
330 | }
331 |
332 |
333 | /*
334 | * Posts and pages
335 | *
336 | * Each post is wrapped in `.post` and is used on default and post layouts. Each
337 | * page is wrapped in `.page` and is only used on the page layout.
338 | */
339 |
340 | .page,
341 | .post {
342 | margin-bottom: 4em;
343 | }
344 |
345 | /* Blog post or page title */
346 | .page-title,
347 | .post-title,
348 | .post-title a {
349 | color: #303030;
350 | }
351 | .page-title,
352 | .post-title {
353 | margin-top: 0;
354 | }
355 |
356 | /* Meta data line below post title */
357 | .post-date {
358 | display: block;
359 | margin-top: -.5rem;
360 | margin-bottom: 1rem;
361 | color: #9a9a9a;
362 | }
363 |
364 | /* Related posts */
365 | .related {
366 | padding-top: 2rem;
367 | padding-bottom: 2rem;
368 | border-top: 1px solid #eee;
369 | }
370 | .related-posts {
371 | padding-left: 0;
372 | list-style: none;
373 | }
374 | .related-posts h3 {
375 | margin-top: 0;
376 | }
377 | .related-posts li small {
378 | font-size: 75%;
379 | color: #999;
380 | }
381 | .related-posts li a:hover {
382 | color: #268bd2;
383 | text-decoration: none;
384 | }
385 | .related-posts li a:hover small {
386 | color: inherit;
387 | }
388 |
389 |
390 | /*
391 | * Pagination
392 | *
393 | * Super lightweight (HTML-wise) blog pagination. `span`s are provide for when
394 | * there are no more previous or next posts to show.
395 | */
396 |
397 | .pagination {
398 | overflow: hidden; /* clearfix */
399 | margin-left: -1rem;
400 | margin-right: -1rem;
401 | font-family: "PT Sans", Helvetica, Arial, sans-serif;
402 | color: #ccc;
403 | text-align: center;
404 | }
405 |
406 | /* Pagination items can be `span`s or `a`s */
407 | .pagination-item {
408 | display: block;
409 | padding: 1rem;
410 | border: 1px solid #eee;
411 | }
412 | .pagination-item:first-child {
413 | margin-bottom: -1px;
414 | }
415 |
416 | /* Only provide a hover state for linked pagination items */
417 | a.pagination-item:hover {
418 | background-color: #f5f5f5;
419 | }
420 |
421 | @media (min-width: 30em) {
422 | .pagination {
423 | margin: 3rem 0;
424 | }
425 | .pagination-item {
426 | float: left;
427 | width: 50%;
428 | }
429 | .pagination-item:first-child {
430 | margin-bottom: 0;
431 | border-top-left-radius: 4px;
432 | border-bottom-left-radius: 4px;
433 | }
434 | .pagination-item:last-child {
435 | margin-left: -1px;
436 | border-top-right-radius: 4px;
437 | border-bottom-right-radius: 4px;
438 | }
439 | }
440 |
--------------------------------------------------------------------------------
/public/images/bg_hr.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/isocpp/CppCoreGuidelines/cb0744e931fd9f441649d9a31b6acdbaa789109d/public/images/bg_hr.png
--------------------------------------------------------------------------------
/public/images/blacktocat.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/isocpp/CppCoreGuidelines/cb0744e931fd9f441649d9a31b6acdbaa789109d/public/images/blacktocat.png
--------------------------------------------------------------------------------
/public/images/icon_download.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/isocpp/CppCoreGuidelines/cb0744e931fd9f441649d9a31b6acdbaa789109d/public/images/icon_download.png
--------------------------------------------------------------------------------
/public/images/sprite_download.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/isocpp/CppCoreGuidelines/cb0744e931fd9f441649d9a31b6acdbaa789109d/public/images/sprite_download.png
--------------------------------------------------------------------------------
/scripts/Makefile:
--------------------------------------------------------------------------------
1 | # This Makefile is supposed to run on the Travis CI server and also locally
2 | # it assumes the nodejs package managaer npm is installed
3 |
4 | # make magic not needed
5 | MAKEFLAGS += --no-builtin-rules
6 | .SUFFIXES:
7 |
8 | BUILD_DIR=build
9 | SOURCEFILE = CppCoreGuidelines.md
10 | SOURCEPATH = ../$(SOURCEFILE)
11 |
12 | .PHONY: default
13 | default: all
14 |
15 | .PHONY: all
16 | all: \
17 | check-markdown \
18 | check-references \
19 | check-notabs \
20 | hunspell-check \
21 | cpplint-all \
22 | check-badchars
23 |
24 | $(BUILD_DIR):
25 | @mkdir -p $(BUILD_DIR)
26 |
27 | #### clean: remove all files generated by the productive rules
28 | .PHONY: clean
29 | clean:
30 | rm -rf $(BUILD_DIR)
31 |
32 | #### distclean: remove all helper executables that may be downloaded by the Makefile
33 | .PHONY: distclean
34 | distclean:
35 | rm -rf ./nodejs/node_modules
36 |
37 |
38 | #### check markdown
39 |
40 | ## run remark markdown checker based on configuration in .remarkrc
41 | .PHONY: check-markdown
42 | check-markdown: nodejs/node_modules/remark nodejs/remark/.remarkrc $(SOURCEPATH) $(BUILD_DIR) Makefile
43 | echo '##################### Markdown check ##################'
44 | ## run remark, paste output to temporary file
45 | cd nodejs; ./node_modules/.bin/remark ../$(SOURCEPATH) --no-color -q --config-path ./remark/.remarkrc 1> ../$(BUILD_DIR)/$(SOURCEFILE).fixed --frail
46 |
47 | ## show a diff with changes remark suggests
48 | .PHONY: show-diff
49 | show-diff: nodejs/node_modules/remark nodejs/remark/.remarkrc $(SOURCEPATH) $(BUILD_DIR) Makefile
50 | cd nodejs; ./node_modules/.bin/remark ../$(SOURCEPATH) --no-color -q --config-path ./remark/.remarkrc 1> ../$(BUILD_DIR)/$(SOURCEFILE).fixed
51 | ## compare temporary file to original, error and fail with message if differences exist
52 | diff $(SOURCEPATH) $(BUILD_DIR)/$(SOURCEFILE).fixed -u3 || \
53 | (echo "Error: remark found bad markdown syntax, see output above" && false)
54 |
55 |
56 | .PHONY: check-references
57 | check-references: $(SOURCEPATH) $(BUILD_DIR) Makefile
58 | @echo '##################### References check ##################'
59 | ## check references unique
60 | @rm -f $(BUILD_DIR)/$(SOURCEFILE).uniq
61 | @cat $(SOURCEPATH) | perl -ne 'print "$$1\n" if (/ $(BUILD_DIR)/$(SOURCEFILE).uniq
62 | ## check if output has data
63 | @if [ -s "build/CppCoreGuidelines.md.uniq" ]; then echo 'Found duplicate anchors:'; cat $(BUILD_DIR)/$(SOURCEFILE).uniq; false; fi
64 |
65 | .PHONY: check-notabs
66 | check-notabs: $(SOURCEPATH) $(BUILD_DIR) Makefile
67 | @echo '##################### Tabs check ##################'
68 | # find lines with tabs
69 | # old file still might be around
70 | @rm -f $(BUILD_DIR)/CppCoreGuidelines.md.tabs
71 | # print file, add line numbers, remove tabs from nl tool, grep for remaining tabs, replace with stars
72 | @cat ../$(SOURCEFILE) | nl -ba | perl -pe 's/(^[^\t]*)\t/$1--/g' | perl -ne 'print if /\t/' | perl -pe 's/\t/\*\*\*\*/g' > $(BUILD_DIR)/$(SOURCEFILE).tabs
73 | @if [ -s $(BUILD_DIR)/CppCoreGuidelines.md.tabs ]; then echo 'Warning: Tabs found:'; cat $(BUILD_DIR)/CppCoreGuidelines.md.tabs; false; fi;
74 |
75 | .PHONY: check-badchars
76 | check-badchars: $(SOURCEPATH) $(BUILD_DIR) Makefile
77 | @echo '##################### Bad chars check ##################'
78 | # find lines with tabs
79 | # old file still might be around
80 | @rm -f $(BUILD_DIR)/CppCoreGuidelines.md.badchars
81 | # print file, add line numbers, grep for bad chars
82 | @cat ../$(SOURCEFILE) | nl -ba | perl -ne 'print if /’|‘|”|“|¸| |–|…|¦/' > $(BUILD_DIR)/$(SOURCEFILE).badchars || true
83 | @if [ -s $(BUILD_DIR)/CppCoreGuidelines.md.badchars ]; then echo 'Warning: Undesired chars (–’‘“”¸…¦) or Unicode EN SPACE found, use markdown-compatible symbols instead:'; cat $(BUILD_DIR)/CppCoreGuidelines.md.badchars; false; fi;
84 |
85 |
86 | .PHONY: hunspell-check
87 | hunspell-check: $(BUILD_DIR)/plain-nohtml.txt
88 | @echo '##################### Spell check ##################'
89 | sed -e 's!http\(s\)\{0,1\}://[^[:space:]]*!!g' build/plain-nohtml.txt | hunspell -d hunspell/en_US -p hunspell/isocpp.dic -u > $(BUILD_DIR)/hunspell-report.txt
90 | @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;
91 |
92 | # only list words that are not in dict
93 | # to include all add them to bottom of hunspell/isocpp.dict, and run
94 | # cat hunspell/isocpp.dic | sort | uniq > hunspell/isocpp.dic2; mv hunspell/isocpp.dic2 hunspell/isocpp.dic
95 | .PHONY: hunspell-list
96 | hunspell-list: $(BUILD_DIR)/plain.txt
97 | sed -e 's!http\(s\)\{0,1\}://[^[:space:]]*!!g' build/plain-nohtml.txt | hunspell -p hunspell/isocpp.dic -l
98 |
99 | #### Cpplint
100 |
101 | .PHONY: cpplint-all
102 | cpplint-all: $(BUILD_DIR)/codeblocks $(BUILD_DIR)/Makefile python/Makefile.in
103 | @echo '##################### C++ Style check ##################'
104 | cd $(BUILD_DIR)/codeblocks; $(MAKE) cpplint-all -k
105 |
106 | #### generic makefile for sourceblocks (need to be evaluated after c++ file generation)
107 |
108 | $(BUILD_DIR)/Makefile: python/Makefile.in
109 | @cp python/Makefile.in $(BUILD_DIR)/codeblocks/Makefile
110 |
111 | #### split md file into plain text and code
112 |
113 | $(BUILD_DIR)/codeblocks: splitfile
114 |
115 | $(BUILD_DIR)/plain.txt: splitfile
116 |
117 | $(BUILD_DIR)/plain-nohtml.txt: $(BUILD_DIR)/plain.txt
118 | sed 's;;;g' $(BUILD_DIR)/plain.txt > $(BUILD_DIR)/plain-nohtml.txt
119 |
120 | .PHONY: splitfile
121 | splitfile: $(SOURCEPATH) ./python/md-split.py
122 | @python ./python/md-split.py $(SOURCEPATH) $(BUILD_DIR)/plain.txt $(BUILD_DIR)/codeblocks
123 |
124 | #### install npm modules
125 | # install/update npm dependencies defined in file package.json
126 | # requires npm (nodejs package manager)
127 | nodejs/node_modules/%: nodejs/package.json
128 | @cd nodejs; npm install
129 |
--------------------------------------------------------------------------------
/scripts/hunspell/en_US.aff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/isocpp/CppCoreGuidelines/cb0744e931fd9f441649d9a31b6acdbaa789109d/scripts/hunspell/en_US.aff
--------------------------------------------------------------------------------
/scripts/hunspell/en_US.dic:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/isocpp/CppCoreGuidelines/cb0744e931fd9f441649d9a31b6acdbaa789109d/scripts/hunspell/en_US.dic
--------------------------------------------------------------------------------
/scripts/hunspell/isocpp.dic:
--------------------------------------------------------------------------------
1 | '
2 | 10'000
3 | 0xFF0000
4 | 0b0101'0101
5 | 10x
6 | '14
7 | 20x
8 | 2D
9 | 2K
10 | 2ndEdition
11 | 2RDU00001
12 | 3rdEdition
13 | 78e
14 | 86xWVb4XIyE
15 | 98's
16 | à
17 | a1
18 | A1
19 | a2
20 | A2
21 | aa
22 | ABA
23 | abi
24 | ABI
25 | ABIs
26 | Abrahams
27 | Abrahams01
28 | abstr
29 | accessor
30 | ack
31 | ACCU
32 | addressof
33 | adl
34 | ADL
35 | Adve
36 | Alexandrescu
37 | Alexandrescu01
38 | algo
39 | alloc
40 | alloc0
41 | ap
42 | API
43 | APIs
44 | archetypical
45 | arg
46 | argh
47 | args
48 | arithmeticcast
49 | arr2
50 | arrayindex
51 | ASIC
52 | asio
53 | AST
54 | async
55 | AUTOSAR
56 | 'B'
57 | b2
58 | BDE
59 | behaviorless
60 | BigTrivial
61 | BigObject
62 | Bjarne
63 | blog
64 | Bloomberg
65 | Boehm
66 | bool
67 | buf
68 | bufmax
69 | bY
70 | C1
71 | C11
72 | C2
73 | callees
74 | callers'
75 | call's
76 | camelCase
77 | CamelCase
78 | CaMelcAse
79 | CaMeLcAsEvArIaBlE
80 | Cargill
81 | Cargill92
82 | cbegin
83 | CComPtr
84 | cend
85 | cerr
86 | chrono
87 | cin
88 | Clang's
89 | class'
90 | clib
91 | Cline99
92 | ClosePort
93 | cm3
94 | cnt
95 | CommonMark
96 | *compiletime
97 | completers
98 | componentization
99 | composability
100 | composable
101 | ComputationCache
102 | conceptsTS
103 | cond
104 | const
105 | Const
106 | constcast
107 | constexpr
108 | constness
109 | constref
110 | copy2
111 | coro
112 | CORBA
113 | cout
114 | CP
115 | cplusplus
116 | Cplusplus
117 | Cplusplus03
118 | CplusplusCS
119 | cpp
120 | cpp98
121 | CppCon
122 | CppCoreCheck
123 | cppcoreguidelines
124 | cppreference
125 | CRTP
126 | cst
127 | cstdarg
128 | cstdio
129 | cstring
130 | cstylecast
131 | ctor
132 | ctors
133 | cxx
134 | cyclomatic
135 | Cyclomatic
136 | czstring
137 | d1
138 | D1
139 | d1's
140 | d2
141 | D2
142 | d2's
143 | dag
144 | DataRecord
145 | dcl
146 | dd
147 | de
148 | Dechev
149 | default0
150 | default00
151 | defop
152 | del
153 | deref
154 | derived1
155 | derived2
156 | destructors
157 | Destructors
158 | detach
159 | Dewhurst
160 | Dewhurst03
161 | disambiguator
162 | draw2
163 | dtor
164 | dtors
165 | dyn
166 | dynarray
167 | ECBS
168 | endl
169 | enum
170 | Enum
171 | enums
172 | EoP
173 | eq
174 | eqdefault
175 | EqualityComparable
176 | errno
177 | expr
178 | f1
179 | f2
180 | f3
181 | f4
182 | fac
183 | Facebook
184 | fallthrough
185 | fallthroughs
186 | faq
187 | fclose
188 | fct
189 | fib10
190 | file1
191 | file2
192 | file3
193 | filesystem
194 | flag1
195 | fmt
196 | fn
197 | fo
198 | foo
199 | Foo
200 | foobar
201 | Foobar
202 | FOOBAR
203 | fopen
204 | fprintf's
205 | fs
206 | func
207 | func1
208 | fx
209 | g1
210 | g2
211 | GCC
212 | Geosoft
213 | getline
214 | getx
215 | GFM
216 | Girou
217 | github
218 | GitHub
219 | GOTW
220 | gp
221 | GPLv3
222 | grep
223 | gsl
224 | GSL
225 | GSL's
226 | gx
227 | handcoded
228 | Henricson
229 | Henricson97
230 | Herlihy
231 | hh
232 | hier
233 | hierclass
234 | hnd
235 | homebrew
236 | HPL
237 | href
238 | HTTP
239 | Hyslop
240 | i2
241 | IDE
242 | identitycast
243 | IDEs
244 | IEC
245 | ifdef
246 | iff
247 | ifstream
248 | impactful
249 | impl
250 | Impl
251 | implicitpointercast
252 | incform
253 | incomplet
254 | incorrekt
255 | increment1
256 | Incrementable
257 | indices
258 | ing
259 | init
260 | inline
261 | inlined
262 | inlining
263 | inout
264 | InputIterator
265 | int32
266 | int64
267 | ints
268 | io
269 | ios
270 | iostream
271 | Iostream
272 | iostreams
273 | iso
274 | isocpp
275 | ISORC
276 | istream
277 | Iter
278 | Jiangang
279 | jmp
280 | join's
281 | JSF
282 | jthread
283 | Juhl
284 | knr
285 | Koenig97
286 | l
287 | Lakos
288 | Lakos96
289 | Lavavej
290 | LCSD05
291 | legacy_class
292 | lifecycle
293 | *life-time
294 | linearization
295 | llvm
296 | lockfree
297 | Lomow
298 | longjmp
299 | LSP
300 | lst
301 | Luchangco
302 | lvalue
303 | lvalues
304 | m1
305 | m2
306 | m3
307 | m_owning;
308 | m_observer;
309 | macros2
310 | malloc
311 | mallocfree
312 | 'many'
313 | Mathematizing
314 | maul2
315 | md
316 | memberinit
317 | members'
318 | memcmp
319 | memcpy
320 | memmove
321 | memoization
322 | memoized
323 | memoizes
324 | memset
325 | metameta
326 | metaprogram
327 | metaprograms
328 | metaprogramming
329 | Metaprogramming
330 | Meyers01
331 | Meyers05
332 | Meyers15
333 | Meyers96
334 | Meyers97
335 | microbenchmarks
336 | middleware
337 | MISRA
338 | mixin
339 | mixins
340 | mnemonizes
341 | modify1
342 | modify2
343 | moredata
344 | *multithreaded
345 | msgsl
346 | mtx
347 | Murray93
348 | mutex
349 | mutexes
350 | mx
351 | My_vector
352 | MyCustomError
353 | MyException
354 | myMap
355 | MyMap
356 | myset
357 | myX
358 | n'
359 | naïvely
360 | namespace
361 | namespaces
362 | Namespaces
363 | NaN
364 | nargs
365 | Naumann
366 | ness
367 | newdelete
368 | nh
369 | Nir
370 | NL
371 | nodiscard
372 | noexcept
373 | noname
374 | nondependent
375 | nonexported
376 | nongeneric
377 | nonlocally
378 | nonprivate
379 | nonreusable
380 | nonvirtual
381 | nonvirtually
382 | nothrow
383 | NR
384 | nullness
385 | nullptr
386 | NVI
387 | ofstream
388 | ok
389 | oo
390 | OO
391 | OOP
392 | OOPSLA'09
393 | oper
394 | optimizable
395 | O'Reilly
396 | org
397 | ostream
398 | ostringstream
399 | overabstract
400 | overconstrain
401 | overconstrained
402 | overridable
403 | overriders
404 | p1
405 | p2
406 | p3
407 | pµÃoorly
408 | Pardoe
409 | parens
410 | passthrough
411 | pb
412 | pb1
413 | pb2
414 | pc
415 | performant
416 | pessimization
417 | picture1
418 | pimpl
419 | Pimpl
420 | Pirkelbauer
421 | PL4
422 | PLDI
423 | Poco
424 | PODs
425 | poly
426 | polymorphically
427 | POPL
428 | PortHandle
429 | PostInitialize
430 | pp216
431 | PPP
432 | pragma
433 | pre
434 | Pre
435 | precomputation
436 | prefetcher
437 | printf
438 | printf's
439 | Proc
440 | productinfo
441 | Productinfo
442 | proto
443 | ps
444 | ptr
445 | ptrdiff
446 | Ptr
447 | ptr2
448 | ptr's
449 | q2
450 | qqq
451 | qsort
452 | R0
453 | r2
454 | raii
455 | RAII
456 | Rc
457 | Rclib
458 | rcon
459 | Rcon
460 | Rconc
461 | Rconst
462 | rcoro
463 | Rcpl
464 | *realtime
465 | Rec2
466 | refactor
467 | refactored
468 | refcount
469 | refcounted
470 | regex
471 | Regex
472 | RegularFunction
473 | reimplement
474 | reinterpretcast
475 | Reis
476 | Reis's
477 | Renum
478 | reseat
479 | reseating
480 | reseats
481 | resizable
482 | rethrow
483 | rethrowing
484 | retryable
485 | *re-use
486 | *re-usable
487 | *re-usability
488 | *Re-usability
489 | reusability
490 | Reusability
491 | rf
492 | Ri
493 | Rl
494 | rnd
495 | Rnr
496 | Ro
497 | Rouquette
498 | Rp
499 | Rper
500 | Rr
501 | rr
502 | RRconc
503 | Rsl
504 | Rstr
505 | RTTI
506 | rvalue
507 | rvalues
508 | RVO
509 | 's
510 | s1
511 | s1's
512 | s2
513 | s3
514 | Sarkar
515 | scanf
516 | Sd
517 | SEI
518 | semiregular
519 | Semiregular
520 | SemiRegular
521 | Sergey
522 | Sewell
523 | SFINAE
524 | Shavit
525 | sharedFoo
526 | sharedness
527 | sharedptrparam
528 | 'sharedptrparam'
529 | setjmp
530 | SignedIntegral
531 | signedness
532 | simpleFunc
533 | 'size'
534 | sizeof
535 | sl
536 | SL
537 | smartptrconcepts
538 | smartptrget
539 | smartptrparam
540 | smartptrs
541 | SMS
542 | Sommerlad
543 | SomeLargeType
544 | SomeOtherFunction
545 | specialization2
546 | spinlock
547 | splonk
548 | splunk
549 | SScp
550 | stdarg
551 | stdlib
552 | Stepanov
553 | stl
554 | STL
555 | stmt
556 | str
557 | strdup
558 | stringification
559 | stringlike
560 | strlen
561 | Str15
562 | Stroustrup
563 | Stroustrup00
564 | Stroustrup05
565 | Stroustrup13
566 | Stroustrup14
567 | Stroustrup15
568 | Stroustrup94
569 | Stroustrup's
570 | struct
571 | structs
572 | subobject
573 | subobjects
574 | suboperations
575 | subsetting
576 | sum1
577 | sum2
578 | supertype
579 | Susmit
580 | SuttAlex05
581 | Sutter
582 | Sutter00
583 | Sutter02
584 | Sutter04
585 | Sutter's
586 | SuttHysl04b
587 | sz
588 | T0
589 | t0
590 | Taligent94
591 | Taligent's
592 | TBD
593 | templated
594 | Templating
595 | templatize
596 | templatized
597 | thread1
598 | thread2
599 | Tjark
600 | tmp
601 | TMP
602 | tock
603 | TODO
604 | tolower
605 | toolchains
606 | TotallyOrdered
607 | TP
608 | tradeoff
609 | TSAN
610 | TSs
611 | tt
612 | typeid
613 | typename
614 | typesafe
615 | UB
616 | u1
617 | u2
618 | UDLs
619 | unaliased
620 | uncompromised
621 | uncopyable
622 | underuse
623 | undetached
624 | unencapsulated
625 | unenforceable
626 | uninit
627 | uniqueptrparam
628 | unittest
629 | unittests
630 | unnamed2
631 | use1
632 | users'
633 | UTF
634 | util
635 | v's
636 | v1
637 | v17
638 | v2
639 | v22
640 | va
641 | ValueType
642 | vararg
643 | varargs
644 | variables'
645 | variadic
646 | Variadic
647 | vbase
648 | vd1
649 | vec
650 | Vector0
651 | Vector1
652 | Vector2
653 | vid
654 | virtuality
655 | virtuals
656 | VLAs
657 | volatile2
658 | vptr
659 | vr
660 | vtable
661 | vtbls
662 | vv
663 | w0
664 | wchar
665 | webby
666 | Webcolor
667 | webcolors
668 | WG21
669 | WidgetUser
670 | WorkQueue
671 | 'widen'
672 | x1
673 | x2
674 | x22
675 | xmax
676 | xor
677 | Xs
678 | y1
679 | y2
680 | years'
681 | yy
682 | Zhuang
683 | zstring
684 | Zubkov
685 | zz
686 |
--------------------------------------------------------------------------------
/scripts/nodejs/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "CppCoreGuidelinesCheck",
3 | "version": "0.0.0",
4 | "description": "CppCoreGuidelines Check",
5 | "private": true,
6 | "dependencies": {
7 | "remark": "^4.2.2",
8 | "remark-lint": "^4.0.2",
9 | "remark-lint-sentence-newline": "^2.0.0",
10 | "remark-validate-links": "^4.1.0"
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/scripts/nodejs/remark/.remarkrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["lint-recommended", "lint-consistent"],
3 | "plugins": {
4 | "remark-lint": {
5 | "unordered-list-marker-style": "consistent",
6 | "list-item-bullet-indent": true,
7 | "list-item-indent": false,
8 | "list-item-spacing": false,
9 | "no-html": false,
10 | "maximum-line-length": false,
11 | "no-file-name-mixed-case": false,
12 | "heading-increment": false,
13 | "no-multiple-toplevel-headings": true,
14 | "no-consecutive-blank-lines": false,
15 | "maximum-line-length": 9000,
16 | "maximum-heading-length": 300,
17 | "no-heading-punctuation": false,
18 | "no-duplicate-headings": false,
19 | "emphasis-marker": "*",
20 | "no-tabs": true,
21 | "blockquote-indentation": false,
22 | "strong-marker": "*"
23 | }
24 | },
25 | "settings": {
26 | "bullet": "*",
27 | "listItemIndent": "1",
28 | "strong": "*",
29 | "emphasis": "*"
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/scripts/python/Makefile.in:
--------------------------------------------------------------------------------
1 | .PHONY: default
2 | default: all
3 |
4 | .PHONY: all
5 | all: \
6 | cpplint-all
7 |
8 | CXX_SRCS := $(wildcard *.cpp)
9 |
10 | #### cpplint, check extracted sources using cpplint tool
11 | CXX_LINT := ${CXX_SRCS:.cpp=.lint}
12 |
13 | .PHONY: cpplint-all
14 | cpplint-all:
15 | @python ../../python/cpplint_wrap.py *.cpp
16 |
17 |
--------------------------------------------------------------------------------
/scripts/python/cpplint_wrap.py:
--------------------------------------------------------------------------------
1 | ## wraps local cpplint to produce verbose output without code harness
2 | import cpplint
3 | import sys
4 |
5 | def main():
6 | FILTERS=('cpplint --verbose=0 --linelength=100 --filter=-legal/copyright,-build/include_order,'
7 | '-build/c++11,-build/namespaces,-build/class,-build/include,-build/include_subdir,-readability/inheritance,'
8 | '-readability/function,-readability/casting,-readability/namespace,-readability/alt_tokens,'
9 | '-readability/braces,-readability/fn_size,-whitespace/comments,-whitespace/braces,-whitespace/empty_loop_body,'
10 | '-whitespace/indent,-whitespace/newline,-runtime/explicit,-runtime/arrays,-runtime/int,-runtime/references,'
11 | '-runtime/string,-runtime/operator,-runtime/printf').split(' ')
12 |
13 | result = False
14 | files = sys.argv[1:]
15 | for loopfile in files:
16 | newargs = FILTERS + [loopfile]
17 | sys.argv = newargs
18 |
19 | try:
20 | cpplint.main()
21 | except SystemExit as e:
22 | last_result = e.args[0]
23 | result = result or last_result
24 | if (last_result):
25 | write_code_lines(loopfile)
26 | sys.exit(result)
27 |
28 | def write_code_lines(filename):
29 | with open(filename, 'r') as f:
30 | linenum = 1
31 | for line in f:
32 | if (not '// by md-split' in line):
33 | sys.stdout.write('%3d %s' % (linenum, line))
34 | linenum += 1
35 |
36 | if __name__ == '__main__':
37 | main()
38 |
--------------------------------------------------------------------------------
/scripts/python/md-split.py:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env python
2 |
3 | # A script that splits a Markdown file into plain text (for spell checking) and c++ files.
4 |
5 |
6 | from __future__ import absolute_import, print_function, unicode_literals
7 |
8 | import os
9 | import shutil
10 | import io
11 | import argparse
12 |
13 | import re
14 | TAG_REGEX = re.compile(r'(|<[^>]*>)')
15 | NAMED_A_TAG_REGEX = re.compile(r'.*name ?= ?"([^"]*)"')
16 |
17 | def main():
18 | """
19 | This script ended up ugly, so in case somebody wants to reimplement, here is the spec that grew by time.
20 |
21 | What it should do it take a markdown file, and split it into more files. A targetfile should have the same
22 | number of lines as the original, with source code snippets and markdown non-words removed, for spell-checking.
23 |
24 | Each code snipped should go into a separate file in codedir.
25 |
26 | Each code snipped should get additional C++ code around it to help compile the line in context, with
27 | some heuristic guessing of what is needed around. The wrapping code should have a token in each line allowing
28 | other tools to filter out these lines
29 |
30 | The name for each file chosen consists os the section id in the markdown document, a counter for the snippet inside the section.
31 |
32 | Snippets without code (only comments) or containing lines starting with ??? should not yeld files,
33 | but the counter for naming snippets should still increment.
34 | """
35 | parser = argparse.ArgumentParser(description='Split md file into plain text and code blocks')
36 | parser.add_argument('sourcefile',
37 | help='which file to read')
38 | parser.add_argument('targetfile',
39 | help='where to put plain text')
40 | parser.add_argument('codedir',
41 | help='where to put codeblocks')
42 | args = parser.parse_args()
43 |
44 | # ensure folder exists
45 | if not os.path.exists(args.codedir):
46 | os.makedirs(args.codedir)
47 |
48 |
49 | if os.path.exists(args.targetfile):
50 | os.remove(args.targetfile)
51 |
52 | code_block_index = 0
53 | last_header = ''
54 | linenum = 0
55 | with io.open(args.sourcefile, 'r') as read_filehandle:
56 | with io.open(args.targetfile, 'w') as text_filehandle:
57 | for line in read_filehandle:
58 | linenum += 1
59 | indent_depth = is_code(line)
60 | if indent_depth:
61 | (line, linenum) = process_code(read_filehandle,
62 | text_filehandle,
63 | line, linenum,
64 | args.sourcefile, args.codedir,
65 | last_header, code_block_index,
66 | indent_depth)
67 | code_block_index += 1
68 | # reach here either line was not code, or was code
69 | # and we dealt with n code lines
70 | if indent_depth < 4 or not is_code(line, indent_depth):
71 | # store header id for codeblock
72 | section_id = get_marker(line)
73 | if section_id is not None:
74 | code_block_index = 0
75 | last_header = section_id
76 | sline = stripped(line)
77 | text_filehandle.write(sline)
78 |
79 | assert line_length(args.sourcefile) == line_length(args.targetfile)
80 |
81 |
82 | def process_code(read_filehandle, text_filehandle, line, linenum, sourcefile, codedir, name, index, indent_depth):
83 | fenced = (line.strip() == '```')
84 | if fenced:
85 | try:
86 | line = read_filehandle.readLine()
87 | linenum += 1
88 | text_filehandle.write('\n')
89 | except StopIteration:
90 | return ('', linenum)
91 | start_linenum = linenum
92 | has_actual_code = False
93 | has_question_marks = False
94 | linebuffer = []
95 | while ((fenced and line.strip() != '```') or (not fenced and is_inside_code(line, indent_depth))):
96 | # copy comments to plain text for spell check
97 | comment_idx = line.find('//')
98 | no_comment_line = line
99 | if comment_idx >= 0:
100 | no_comment_line = line[:comment_idx].strip()
101 | text_filehandle.write(line[comment_idx + 2:])
102 | else:
103 | # write empty line so line numbers stay stable
104 | text_filehandle.write('\n')
105 |
106 | if (not has_actual_code
107 | and not line.strip().startswith('//')
108 | and not line.strip().startswith('???')
109 | and not line.strip() == ''):
110 | has_actual_code = True
111 |
112 | if (not line.strip() == '```'):
113 | if ('???' == no_comment_line or '...' == no_comment_line):
114 | has_question_marks = True
115 | linebuffer.append(dedent(line, indent_depth) if not fenced else line)
116 | try:
117 | line = read_filehandle.readline()
118 | linenum += 1
119 | except StopIteration:
120 | line = ''
121 | break
122 | codefile = os.path.join(codedir, '%s%s.cpp' % (name, index))
123 | if fenced:
124 | text_filehandle.write('\n')
125 |
126 | if (has_actual_code and not has_question_marks):
127 | linebuffer = clean_trailing_newlines(linebuffer)
128 | write_with_harness(codefile, sourcefile, start_linenum, linebuffer)
129 | return (line, linenum)
130 |
131 |
132 | def clean_trailing_newlines(linebuffer):
133 | result = []
134 | code_started = False
135 | linebuffer.reverse()
136 | for line in linebuffer:
137 | if not code_started and line == '\n':
138 | continue
139 | code_started = True
140 | result.append(line)
141 | result.reverse()
142 | return result
143 |
144 |
145 | def write_with_harness(codefile, sourcefile, start_linenum, linebuffer):
146 | '''write output with additional lines to make code likely compilable'''
147 | # add commonly used headers, so that lines can likely compile.
148 | # This is work in progress, the main issue remains handling class
149 | # declarations in in-function code differently
150 | with io.open(codefile, 'w') as code_filehandle:
151 | code_filehandle.write('''\
152 | #include