All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.plugins.javascript.eslint.tsconfig.LookupTsConfigProvider Maven / Gradle / Ivy

There is a newer version: 10.17.0.28100
Show newest version
/*
 * SonarQube JavaScript Plugin
 * Copyright (C) 2011-2022 SonarSource SA
 * mailto:info AT sonarsource DOT com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package org.sonar.plugins.javascript.eslint.tsconfig;

import java.io.File;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;

class LookupTsConfigProvider implements Provider {

  private static final Logger LOG = Loggers.get(LookupTsConfigProvider.class);

  @Override
  public List tsconfigs(SensorContext context) {
    var fs = context.fileSystem();
    var tsconfigs = new ArrayList();
    var dirs = new ArrayDeque();
    dirs.add(fs.baseDir());
    while (!dirs.isEmpty()) {
      var dir = dirs.removeFirst();
      var files = dir.listFiles();
      if (files == null) {
        continue;
      }
      for (var file : files) {
        if (file.isDirectory() && !"node_modules".equals(file.getName())) {
          dirs.add(file);
        } else if ("tsconfig.json".equals(file.getName())) {
          tsconfigs.add(file.getAbsolutePath());
        }
      }
    }
    LOG.info("Found " + tsconfigs.size() + " tsconfig.json file(s): " + tsconfigs);
    return tsconfigs;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy