function handleModuleCase()

in rules/file-name.js [35:57]


function handleModuleCase(node, context, defaultFilename) {
    if (context.parserOptions.sourceType !== 'module') {
        return defaultFilename;
    }

    // Handle the module case.
    var name = node.arguments[1].name;
    var globalScope = context.getScope();

    // Retrieve the import instruction.
    var variable = globalScope.variables.find(function(v) {
        return v.name === name;
    });

    // Check that the definition is an import declaration.
    if (!(variable && variable.defs && variable.defs[0] && variable.defs[0].parent && variable.defs[0].parent.type === 'ImportDeclaration')) {
        return defaultFilename;
    }

    // Thanks to the chrome devtools to find the path of the filename. :-)
    var filename = path.basename(variable.defs[0].parent.source.value);
    return filename;
}