Skip to content

Commit d4d2496

Browse files
authored
Add maint script: find_unused_settings.py. NFC (#24869)
Does what it says on the tin. I wrote this suspecting we might have some but it turns out we don't. Adding the script anyway as it could be useful in future and as the basis for other such scripts.
1 parent d4537ff commit d4d2496

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tools/maint/find_unused_settings.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python3
2+
"""Find unused settings from settings.js and settings_internal.js.
3+
"""
4+
5+
import os
6+
import subprocess
7+
import sys
8+
9+
script_dir = os.path.dirname(os.path.abspath(__file__))
10+
root_dir = os.path.dirname(os.path.dirname(script_dir))
11+
12+
sys.path.insert(0, root_dir)
13+
14+
# This avoiding including `LEGACY_SETTINGS`
15+
os.environ['EMCC_STRICT'] = '1'
16+
17+
from tools.settings import settings
18+
19+
20+
def main():
21+
print(f'Searching {len(settings.attrs)} settings')
22+
for key in settings.attrs:
23+
cmd = ['git', 'grep', '-q', f'\\<{key}\\>', ':(exclude)src/settings.js', ':(exclude)src/settings_internal.js']
24+
print('CHECKING:', key)
25+
# git grep returns 0 if there is a match and non-zero when there is not
26+
if subprocess.run(cmd, check=False).returncode:
27+
print('NOT FOUND: ', key)
28+
29+
30+
if __name__ == '__main__':
31+
sys.exit(main())

0 commit comments

Comments
 (0)