Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Change spellchecking tool and fix spelling mistakes #7765

Merged
merged 18 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ module.exports = {
'no-sequences': 'error',
'no-throw-literal': 'error',
'no-unmodified-loop-condition': 'error',
'no-unused-vars': 'off', // Interface impls may not require all args
// Interface implementations may not require all args
'no-unused-vars': 'off',
'no-useless-call': 'error',
'no-useless-catch': 'error',
'no-useless-concat': 'error',
Expand Down Expand Up @@ -167,6 +168,7 @@ module.exports = {
...commonNoRestrictedSyntax,
],
'no-whitespace-before-property': 'error',
// cspell: disable-next-line
'nonblock-statement-body-position': ['error', 'below'],
'operator-assignment': 'error',
'spaced-comment': ['error', 'always', {
Expand Down
51 changes: 15 additions & 36 deletions build/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,45 +150,24 @@ def check_complete(_):
return False
return True


@_Check('spelling')
def check_spelling(_):
"""Checks that source files don't have any common misspellings."""
logging.info('Checking for common misspellings...')

complete_build = complete_build_files()
if not complete_build:
return False

logging.info('Checking for spelling mistakes...')
base = shakaBuildHelpers.get_source_base()
complete_build.update(shakaBuildHelpers.get_all_js_files('test'))
complete_build.update(shakaBuildHelpers.get_all_js_files('demo'))
complete_build.update(shakaBuildHelpers.get_all_js_files('externs'))
complete_build.update(shakaBuildHelpers.get_all_files(
os.path.join(base, 'build'), re.compile(r'.*\.(js|py)$')))

with shakaBuildHelpers.open_file(
os.path.join(base, 'build', 'misspellings.txt')) as f:
misspellings = ast.literal_eval(f.read())
has_error = False
for path in complete_build:
with shakaBuildHelpers.open_file(path) as f:
for i, line in enumerate(f):
for regex, replace_pattern in misspellings.items():
for match in re.finditer(regex, line):
repl = match.expand(replace_pattern).lower()
if match.group(0).lower() == repl:
continue # No-op suggestion

if not has_error:
logging.error('The following file(s) have misspellings:')
logging.error(
' %s:%d:%d: Did you mean %r?' %
(os.path.relpath(path, base), i + 1, match.start() + 1, repl))
has_error = True

return not has_error

config_path = os.path.join(base, 'cspell.config.yaml')
lint_files = get_lint_files()
py_match = re.compile(r'.*\.py$')
py_files = shakaBuildHelpers.get_all_files(
os.path.join(base, 'build'), py_match)
md_match = re.compile(r'.*\.md$')
md_files = shakaBuildHelpers.get_all_files(
os.path.join(base, 'docs'), md_match)
cspell = shakaBuildHelpers.get_node_binary('cspell')
cmd_line = cspell + ['--config=' + config_path] + ['--no-progress']
cmd_line += lint_files + md_files + py_files
if shakaBuildHelpers.execute_get_code(cmd_line) != 0:
return False
return True

@_Check('eslint_disable')
def check_eslint_disable(_):
Expand Down
2 changes: 1 addition & 1 deletion build/generateExterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function getLeadingBlockComment(node) {
}

// In case there are multiple (for example, a file-level comment that also
// preceeds the node), take the most recent one, which is closest to the node.
// precedes the node), take the most recent one, which is closest to the node.
const mostRecentComment = blockComments[blockComments.length - 1];

// Reconstruct the original block comment by adding back /* and */.
Expand Down
2 changes: 2 additions & 0 deletions build/generateLocalizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# cspell:words Merin haryalye alasse

"""Generates Javascript to load compile-time localization data.

This reads localization data at compile-time in a flat JSON-formatted
Expand Down
2 changes: 1 addition & 1 deletion build/generateTsDefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def GenerateTsDefs(inputs, output):
global_error_def = b'declare class GlobalError extends Error {}\n\n'
contents = global_error_def + contents
# There are some types that implement multiple interfaces, such as IReleasable
# and Iteratable. Also, there are tools used inside Google that (for some
# and Iterable. Also, there are tools used inside Google that (for some
# reason) want to convert TS defs _BACK_ into Closure Compiler externs. When
# that happens, these multiple implementors generate externs with broken
# @implements annotations. Since this team can't control that process or
Expand Down
48 changes: 0 additions & 48 deletions build/misspellings.txt

This file was deleted.

2 changes: 2 additions & 0 deletions build/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# cspell:ignore goverlap neato tsvg

"""A program for analyzing the Shaka compiled sources.

This can be used to find areas that can be removed if not needed. This uses
Expand Down
18 changes: 18 additions & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
$schema: https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json
version: '0.2'
language: en
dictionaryDefinitions:
- name: project-words
path: ./project-words.txt
addWords: true
dictionaries:
- en_US
- en-gb
- typescript
- python
- project-words
ignorePaths:
- node_modules
- dist
- externs/*.js
- /project-words.txt
10 changes: 5 additions & 5 deletions demo/asset_card.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ shakaDemo.AssetCard = class {
this.featureIconsContainer_ = document.createElement('div');
/** @private {!Element} */
this.progressCircle_ = document.createElement('div');
const svgns = 'http://www.w3.org/2000/svg';
const svgNs = 'http://www.w3.org/2000/svg';
/** @private {!Element} */
this.progressCircleSvg_ = document.createElementNS(svgns, 'svg');
this.progressCircleSvg_ = document.createElementNS(svgNs, 'svg');
/** @private {!Element} */
this.progressCircleBack_ = document.createElementNS(svgns, 'circle');
this.progressCircleBack_ = document.createElementNS(svgNs, 'circle');
/** @private {!Element} */
this.progressCircleBar_ = document.createElementNS(svgns, 'circle');
this.progressCircleBar_ = document.createElementNS(svgNs, 'circle');
/** @private {function(!shakaDemo.AssetCard)} */
this.remakeButtonsFn_ = remakeButtonsFn;

Expand Down Expand Up @@ -307,7 +307,7 @@ shakaDemo.AssetCard = class {
addStoreButton() {
/**
* Makes the contents of the button into an MDL icon, and moves it into the
* upper-righthand corner with CSS styles.
* upper-right hand corner with CSS styles.
tykus160 marked this conversation as resolved.
Show resolved Hide resolved
* @param {!Element} button
* @param {!Element} attachPoint If there is no attach point, just pass the
* button in here.
Expand Down
2 changes: 1 addition & 1 deletion demo/cast_receiver/receiver_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class ShakaReceiverApp {
this.idleTimerId_ = null;
}
}
} // class ShakaRecevierApp
} // class ShakaReceiverApp

/**
* @const {number}
Expand Down
Loading
Loading