[javascriptlint-commit] SF.net SVN: javascriptlint:[375] trunk
Status: Beta
Brought to you by:
matthiasmiller
From: <mat...@us...> - 2018-01-02 21:26:52
|
Revision: 375 http://sourceforge.net/p/javascriptlint/code/375 Author: matthiasmiller Date: 2018-01-02 21:26:49 +0000 (Tue, 02 Jan 2018) Log Message: ----------- Add a configuration setting for additional include directories. Modified Paths: -------------- trunk/javascriptlint/conf.py trunk/javascriptlint/lint.py trunk/test.py Added Paths: ----------- trunk/tests/path_resolution/include_dir.js trunk/tests/path_resolution/include_dir_a/ trunk/tests/path_resolution/include_dir_a/import_helper.js trunk/tests/path_resolution/include_dir_b/ trunk/tests/path_resolution/include_dir_b/import_helper.js trunk/tests/path_resolution/include_dir_b/import_helper_b.js Modified: trunk/javascriptlint/conf.py =================================================================== --- trunk/javascriptlint/conf.py 2018-01-02 21:20:15 UTC (rev 374) +++ trunk/javascriptlint/conf.py 2018-01-02 21:26:49 UTC (rev 375) @@ -188,6 +188,18 @@ self._conf.loadfile(parm) self.value = parm +class IncludeDirSetting(Setting): + wants_parm = True + wants_dir = True + def __init__(self): + self.value = [] + def load(self, enabled, parm, dir): + if not dir: + raise ConfError('The %s setting is only valid in a configuration file.' % parm) + + abs_dir = os.path.abspath(os.path.join(dir, parm)) + self.value.append(abs_dir) + class Conf: def __init__(self): recurse = BooleanSetting(False) @@ -203,6 +215,7 @@ 'process': ProcessSetting(recurse), 'default-version': JSVersionSetting(), 'conf': ConfSetting(self), + 'include-dir': IncludeDirSetting(), # SpiderMonkey warnings 'no_return_value': BooleanSetting(True), 'equal_as_assign': BooleanSetting(True), Modified: trunk/javascriptlint/lint.py =================================================================== --- trunk/javascriptlint/lint.py 2018-01-02 21:20:15 UTC (rev 374) +++ trunk/javascriptlint/lint.py 2018-01-02 21:26:49 UTC (rev 375) @@ -283,12 +283,14 @@ # The user can specify paths using backslashes (such as when # linting Windows scripts on a posix environment. import_path = import_path.replace('\\', os.sep) - import_path = os.path.join(os.path.dirname(path), import_path) - if os.path.isfile(import_path): - return lint_file(import_path, 'js', jsversion, encoding) + include_dirs = [os.path.dirname(path)] + conf['include-dir'] + for include_dir in include_dirs: + abs_path = os.path.join(include_dir, import_path) + if os.path.isfile(abs_path): + return lint_file(abs_path, 'js', jsversion, encoding) _report(offset, 'error', 'io_error', { - 'error': 'The file could not be found: %s' % import_path + 'error': 'The file could not be found in any include paths: %s' % import_path }) return _Script() Modified: trunk/test.py =================================================================== --- trunk/test.py 2018-01-02 21:20:15 UTC (rev 374) +++ trunk/test.py 2018-01-02 21:26:49 UTC (rev 375) @@ -21,12 +21,12 @@ class TestError(Exception): pass -def _get_conf(script): +def _get_conf(script, script_dir): regexp = re.compile(r"/\*conf:([^*]*)\*/") text = '\n'.join(regexp.findall(script)) conf = javascriptlint.conf.Conf() - conf.loadtext(_DEFAULT_CONF) - conf.loadtext(text) + conf.loadtext(_DEFAULT_CONF, script_dir) + conf.loadtext(text, script_dir) return conf def _get_expected_warnings(script): @@ -45,11 +45,14 @@ return warnings def _testfile(path): + script_dir = os.path.dirname(path) + assert os.path.isabs(script_dir) + # Parse the script and find the expected warnings. script = open(path).read() expected_warnings = _get_expected_warnings(script) unexpected_warnings = [] - conf = _get_conf(script) + conf = _get_conf(script, script_dir) def lint_error(path, line, col, msg_type, errname, errdesc): warning = (line, msg_type, errname) Added: trunk/tests/path_resolution/include_dir.js =================================================================== --- trunk/tests/path_resolution/include_dir.js (rev 0) +++ trunk/tests/path_resolution/include_dir.js 2018-01-02 21:26:49 UTC (rev 375) @@ -0,0 +1,5 @@ +/*conf:+include-dir include_dir_a*/ + +/*jsl:import import_helper.js*/ +/*jsl:import import_helper_b.js*/ /*error:io_error*/ +import_helper(); Added: trunk/tests/path_resolution/include_dir_a/import_helper.js =================================================================== --- trunk/tests/path_resolution/include_dir_a/import_helper.js (rev 0) +++ trunk/tests/path_resolution/include_dir_a/import_helper.js 2018-01-02 21:26:49 UTC (rev 375) @@ -0,0 +1,2 @@ +function import_helper() { +} Added: trunk/tests/path_resolution/include_dir_b/import_helper.js =================================================================== Added: trunk/tests/path_resolution/include_dir_b/import_helper_b.js =================================================================== This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |