material-components_materia.../scripts/check/missing_example_language
Jeff Verkoeyen 2cb18a209b Add missing example language check.
Summary:
Example output:

```
Each of the following components is missing example language:
components/FlexibleHeader/README.md:131
components/FlexibleHeader/README.md:159
components/FlexibleHeader/README.md:231
components/FlexibleHeader/README.md:322
components/FlexibleHeader/README.md:352
components/HeaderStackView/README.md:88
components/Ink/README.md:90
components/Ink/README.md:109
components/Ink/README.md:142
components/PageControl/README.md:121
components/PageControl/README.md:170
components/ShadowElevations/README.md:71
components/ShadowLayer/README.md:104
components/ShadowLayer/README.md:125
components/ShadowLayer/README.md:140
components/ShadowLayer/README.md:166
components/Slider/README.md:76
components/Switch/README.md:80
```

Reviewers: #mdc_ios_owners, ajsecord

Reviewed By: #mdc_ios_owners, ajsecord

Projects: #material_components_ios

Differential Revision: http://codereview.cc/D572
2016-04-12 14:37:52 -04:00

41 lines
1.4 KiB
PHP
Executable File

#!/usr/bin/php
<?php
#
# Copyright 2016-present Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
exec("find components -name 'README.md'", $output);
foreach ($output as $file) {
$contents = file_get_contents($file);
if (preg_match_all('/<\!--<div class="material-code-render" markdown="1">-->(.+?)<\!--<\/div>-->/sm',
$contents, $matches, PREG_OFFSET_CAPTURE)) {
foreach ($matches[1] as $match) {
$passes = false;
if (preg_match_all('/~~~ objc(.+?)~~~.+?~~~ swift(.+?)~~~/sm', $match[0], $languages)) {
$objc = trim($languages[1][0]);
$swift = trim($languages[2][0]);
if (!empty($objc) && !empty($swift)) {
$passes = true;
}
}
if (!$passes) {
list($before) = str_split($contents, $match[1]);
$line_number = strlen($before) - strlen(str_replace("\n", "", $before)) + 1;
echo "$file:$line_number\n";
}
}
}
}