Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
Add tools/runlint.py, which will be automatically run by khan-linter.
Browse files Browse the repository at this point in the history
Summary:
If you install the standard pre-commit hook on the git repo, this will
be run on every file you change, so you can make sure you're only
committing lint-clean code.

Modify the blacklist to actually lint the html in exercises/.

I don't know why exercises/ was excluded before.  Probably by
accident.

I also added linting of .git/, because linting stuff in there is just
wasted effort.

Fix up a few lint errors before turning on the linter.

We don't want to have raw $._() in code, they should only be in the
"vars" section where we can properly translate them.  I guess.

Fix a place lint_i18n_strings doesn't work right by using i18nDoNotTranslate.

lint_i18n_strings doesn't realize that \text{label + ":"} does not
actually have any natural-language text in it, so it wants to
translate it.  Fixing this looks in source looks unduly complicated,
so for now I fix it by wrapping this construct in the new
i18nDoNotTranslate.  It's good practice for it anyway!

I also fixed up finding_percents.html, which I had incorrectly fixed
last time.

Test Plan:
Ran
   tools/runlint.py exercises/*
and got the same behavior as when I ran lint_i18n_files over
everything.  However, it didn't barf on exercises/test like
lint_i18n_files does.

I also ran
   tools/runlint.py *.js && echo hi
and it printed 'hi', since there's nothing to lint (yet!) in the *.js
files.

Ran
   make lint
and saw error mesages like:
   /home/csilvers/khan/third_party/khan-exercises/exercises/unit_circle.html:1: E212 1 node need to be fixed. Run build/lint_i18n_strings.py with --fix to automatically fix them.

but no other errors; that is, the linter is running our new runlint,
but nothing else that is introducing errors.

(Will test with the rest of the lint fixes later.)

Ran
   python -mSimpleHTTPServer
and visited
   http://localhost:8000/exercises/inequalities_on_a_number_line.html
and reloaded until I got 'which graph on the number line
represents...' and verified the label before each graph ("A", "B",
"C", etc) displayed correctly, and without javascript errors.

I also tested
   http://localhost:8000/exercises/arithmetic_word_problems_2.html
   http://localhost:8000/exercises/comparing_decimals_1.html
   http://localhost:8000/exercises/completing_the_square_1.html
   http://localhost:8000/exercises/completing_the_square_2.html
   http://localhost:8000/exercises/dividing_fractions_word_problems.html
   http://localhost:8000/exercises/finding_percents.html
looking at both text and hints (and the javascript error console!), to
make sure the previous commit is also still ok.

Reviewers: eater, alpert

Reviewed By: alpert

Differential Revision: http://phabricator.khanacademy.org/D3904
  • Loading branch information
csilvers committed Sep 12, 2013
1 parent b7d479e commit 3e985ac
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 42 deletions.
3 changes: 2 additions & 1 deletion exercises/arithmetic_word_problems_2.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
])</var>
<var id="DISTANCE_PER_DAY">$._("%(distance_unit)s per day", {distance_unit: plural_form(distance( 1, NUM1 ))})</var>
<var id="DAYS">$._("days")</var>
<var id="ROWS">$._("rows")</var>
<var id="DAYS_BIKING">$._("number of days %(BIKING)s", {BIKING: BIKING})</var>
<var id="ROWS_OF_CROPS">$._("rows of %(crop)s", {crop: plural_form(crop( 1 ))})</var>
<var id="CROPS_PER_ROW">$._("%(crop)s per row", {crop: plural_form(crop( 1 ))})</var>
Expand Down Expand Up @@ -317,7 +318,7 @@
The result, called the quotient, is <code><var>TOTAL</var>\text{ <var>plural_form(crop( 1 ), TOTAL)</var>} \div <var>NUM1</var>\text{ <var>CROPS_PER_ROW</var>}</code>.
</p>
<p>
<code><var>TOTAL</var>\text{ <var>plural( crop( 1 ) )</var>} \div <var>NUM1</var>\text{ <var>CROPS_PER_ROW</var>} = <var>NUM2</var>\text{ <var>$._("rows")</var>}</code>
<code><var>TOTAL</var>\text{ <var>plural( crop( 1 ) )</var>} \div <var>NUM1</var>\text{ <var>CROPS_PER_ROW</var>} = <var>NUM2</var>\text{ <var>ROWS</var>}</code>
</p>
</div>
</div>
Expand Down
7 changes: 4 additions & 3 deletions exercises/comparing_decimals_1.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
}
})()
</var>
<var id="HUNDREDTHS">$._("hundredths")</var>
</div>

<div class="problem">
Expand Down Expand Up @@ -188,13 +189,13 @@
</div>

<p data-if="N1 === N2">
<code>\large{\blue{<var>D1</var> \text{ <var>$._("hundredths")</var>}}}</code> is the same as <code>\large{\green{<var>D2</var> \text{ <var>$._("hundredths")</var>}}}</code>.
<code>\large{\blue{<var>D1</var> \text{ <var>HUNDREDTHS</var>}}}</code> is the same as <code>\large{\green{<var>D2</var> \text{ <var>HUNDREDTHS</var>}}}</code>.
</p>
<p data-else-if="N1 &gt; N2">
<code>\large{\blue{<var>D1</var> \text{ <var>$._("hundredths")</var>}}}</code> is more than <code>\large{\green{<var>D2</var> \text{ <var>$._("hundredths")</var>}}}</code>.
<code>\large{\blue{<var>D1</var> \text{ <var>HUNDREDTHS</var>}}}</code> is more than <code>\large{\green{<var>D2</var> \text{ <var>HUNDREDTHS</var>}}}</code>.
</p>
<p data-else="">
<code>\large{\blue{<var>D1</var> \text{ <var>$._("hundredths")</var>}}}</code> is less than <code>\large{\green{<var>D2</var> \text{ <var>$._("hundredths")</var>}}}</code>.
<code>\large{\blue{<var>D1</var> \text{ <var>HUNDREDTHS</var>}}}</code> is less than <code>\large{\green{<var>D2</var> \text{ <var>HUNDREDTHS</var>}}}</code>.
</p>

<p data-if="N1 === N2">Therefore <code>\large{<var>N1</var>}</code> = <code>\large{<var>N2</var>}</code>.</p>
Expand Down
5 changes: 3 additions & 2 deletions exercises/completing_the_square_1.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<var id="C">X1 * X2</var>
<var id="POLY">new Polynomial( 0, 2, [C, B, 1], "x" )</var>
<var id="POLY_TEXT">POLY.text()</var>
<var id="OR">$._("or")</var>
</div>
<p class="question">Complete the square to solve for <code>x</code>.</p>
<p><code><var>POLY_TEXT</var> = 0</code></p>
Expand All @@ -38,7 +39,7 @@
<b>Completed Square:</b> <br>
<code>(x + {}</code><span class="sol short32"></span> <code>)^2 = {}</code> <span class="sol short32"></span> <br><br>
<b>Solution:</b> <br>
<code>x = {}</code><span class="sol short32"></span><code>\quad\text{<var>$._("or")</var>}\quad x = {}</code><span class="sol short32"></span>
<code>x = {}</code><span class="sol short32"></span><code>\quad\text{<var>OR</var>}\quad x = {}</code><span class="sol short32"></span>
</div>
</div>
</div>
Expand Down Expand Up @@ -89,7 +90,7 @@
</div>
<div>
<div data-if="sqrt( C * -1 + pow( B / 2, 2 ) ) !== 0">
<p>So the solutions are: <code>x = <var>-B / 2 + sqrt( C * -1 + pow( B / 2, 2 ) )</var> \text{ <var>$._("or")</var> } x = <var>-B / 2 - sqrt( C * -1 + pow( B / 2, 2 ) )</var></code></p>
<p>So the solutions are: <code>x = <var>-B / 2 + sqrt( C * -1 + pow( B / 2, 2 ) )</var> \text{ <var>OR</var> } x = <var>-B / 2 - sqrt( C * -1 + pow( B / 2, 2 ) )</var></code></p>
</div>
<div data-else="">
<p>The solution is: <code>x = <var>-B / 2 + sqrt( C * -1 + pow( B / 2, 2 ) )</var></code></p>
Expand Down
2 changes: 1 addition & 1 deletion exercises/completing_the_square_2.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<b>Completed Square:</b> <br>
<code>(x + {}</code><span class="sol short32"></span> <code>)^2 = {}</code> <span class="sol short40"></span> <br><br>
<b>Solution:</b> <br>
<code>x = {}</code><span class="sol short32"></span><code>\quad\text{<var>$._("or")</var>}\quad x = {}</code><span class="sol short32"></span>
<code>x = {}</code><span class="sol short32"></span><code>\quad\text{<var>OR</var>}\quad x = {}</code><span class="sol short32"></span>
</div>
</div>
<p class="example">integers, like <code>6</code></p>
Expand Down
13 changes: 8 additions & 5 deletions exercises/dividing_fractions_word_problems.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
<var id="MILE_PER_SWIMMER">$._("mile per swimmer")</var>
<var id="NUMBER_OF_SWIMMERS">$._("number of swimmers")</var>
<var id="SWIMMERS_PER_MILE">$._("swimmers per mile")</var>
<var id="SWIMMERS">$._("swimmers")</var>
</div>

<div class="problem">
Expand Down Expand Up @@ -234,7 +235,7 @@
</code></p>
<p><code>
\phantom{<var>MILES</var>\text{ <var>plural_form(MILE, MILES)</var>} \times
<var>D</var> \text{ <var>SWIMMERS_PER_MILE</var>}} = \green{<var>D * MILES</var> \text{ <var>$._("swimmers")</var>}}
<var>D</var> \text{ <var>SWIMMERS_PER_MILE</var>}} = \green{<var>D * MILES</var> \text{ <var>SWIMMERS</var>}}
</code></p>

<p data-if="isMale(1)"><var>person(1)</var> needs <var>SOLUTION</var> swimmers on his team.</p>
Expand All @@ -254,6 +255,7 @@
})
</var>
<var id="BAGS_PER_POUND">$._("bags per pound")</var>
<var id="GIFT_BAGS">$._("gift bags")</var>
</div>

<p class="problem" data-if="isMale(1)">
Expand All @@ -280,7 +282,7 @@
</p>
<p><code>
\dfrac{\red{<var>CHOCOLATE</var> \text{ <var>plural_form(POUNDS, CHOCOLATE)</var>}}}
{\color{<var>BLUE</var>}{\dfrac{1}{<var>D</var>} \text{ <var>POUND_PER_BAG</var>}}} = \green{\text{ <var>$._("gift bags")</var>}}
{\color{<var>BLUE</var>}{\dfrac{1}{<var>D</var>} \text{ <var>POUND_PER_BAG</var>}}} = \green{\text{ <var>GIFT_BAGS</var>}}
</code></p>
<p>Dividing by a fraction is the same as multiplying by the reciprocal.</p>
<p>
Expand All @@ -290,11 +292,11 @@
<p><code>
\red{<var>CHOCOLATE</var>\text{ <var>POUND_PER_BAG</var>}} \times
\green{<var>D</var> \text{ <var>BAGS_PER_POUND</var>}}
= \green{\text{ <var>$._("gift bags")</var>}}
= \green{\text{ <var>GIFT_BAGS</var>}}
</code></p>
<p><code>
\phantom{<var>CHOCOLATE</var>\text{ <var>POUND_PER_BAG</var>} \times <var>D</var> \text{ <var>BAGS_PER_POUND</var>}}
= \green{<var>D * CHOCOLATE</var> \text{ <var>$._("gift bags")</var>}}
= \green{<var>D * CHOCOLATE</var> \text{ <var>GIFT_BAGS</var>}}
</code></p>
<p><var>person(1)</var> could create <var>SOLUTION</var> gift bags.</p>
</div>
Expand All @@ -312,6 +314,7 @@
<var id="HOUR_PER_EXERCISE">$._("hour per exercise")</var>
<var id="NUMBER_OF_EXERCISES">$._("number of exercises")</var>
<var id="EXERCISES_PER_HOUR">$._("exercises per hour")</var>
<var id="EXERCISES">$._("exercises")</var>
</div>

<p class="problem" data-if="isMale(1)">
Expand Down Expand Up @@ -352,7 +355,7 @@
</code></p>
<p><code>
\phantom{<var>HOURS</var>\text{ <var>plural_form(HOUR, HOURS)</var>} \times <var>D</var> \text{ <var>EXERCISES_PER_HOUR</var>}}
= \green{<var>D * HOURS</var> \text{ <var>$._("exercises")</var>}}
= \green{<var>D * HOURS</var> \text{ <var>EXERCISES</var>}}
</code></p>
<p><var>person(1)</var> can do <var>SOLUTION</var> different types of exercise per workout.</p>
</div>
Expand Down
Loading

0 comments on commit 3e985ac

Please sign in to comment.